Wednesday, March 28, 2018

Korean characters become "???" after exported using dompdf laravel - development

Korean characters become "???" after exported using dompdf laravel

I using dompdf for laravel, the problem is the Korean characters can show properly in html but it’s turn into “???” when exported into pdf.

Korean characters in header and footer can show properly using $canvas->page_script() but Korean characters in loadHTML not showing properly.

Can someone help me?

        $pdf->loadHTML($doc_content);
        $pdf->output();
        $dom_pdf = $pdf->getDomPDF();
        $options = new Options();
        $options->set('isPhpEnabled', true);
        $options->set('isRemoteEnabled', true);
        $options->set('defaultFont', 'UnShinmun');
        $dom_pdf->setOptions($options);
        $canvas = $dom_pdf->get_canvas();
        //$canvas->page_text(0, 0, "Page {PAGE_NUM} of {PAGE_COUNT}", null, 10, array(0, 0, 0));

        $canvas->page_script('              
            $font = $fontMetrics->get_font("UnShinmun");
            $size = 11;

            $pageText = "'.$doc_title.'";
            $y = 30;
            $x = $pdf->get_width()-30- $fontMetrics->get_text_width($pageText, $font, $size);
            $pdf->text($x, $y, $pageText, $font, $size, array(.302, .302, .302));

            $pageText = "'.$doc_num.'";
            $y = 44;
            $x = $pdf->get_width()-30- $fontMetrics->get_text_width($pageText, $font, $size);
            $pdf->text($x, $y, $pageText, $font, $size, array(.302, .302, .302));

            $size = 9;

            $pageText = "Page " . $PAGE_NUM. " of " . $PAGE_COUNT;
            $y = $pdf->get_height() - 38;
            $x = $pdf->get_width()-30- $fontMetrics->get_text_width($pageText, $font, $size);
            $pdf->text($x, $y, $pageText, $font, $size, array(.302, .302, .302));

            $pageText = "'.($type=='Form'?'':'Version No.: 01').'";
            $y = $pdf->get_height() - 38;
            $x2 = 28;
            $pdf->text($x2, $y, $pageText, $font, $size, array(.302, .302, .302));

            $y = $pdf->get_height() - 24;
            $pageText = "V' . '1.00' . '";
            $pdf->text($x, $y, $pageText, $font, $size, array(.302, .302, .302));               
            $pdf->line(28,795,567,795,array(.302, .302, .302),1); #footer hr
       ');
        //$pdf->render();
        $output = $pdf->output();



from Laravel Questions and Answers https://laravelquestions.com/laravel/korean-characters-become-after-exported-using-dompdf-laravel/
via Lzo Media

No comments:

Post a Comment