spipu / html2pdf

OFFICIAL PROJECT | HTML to PDF converter written in PHP
http://html2pdf.fr/en/default
Open Software License 3.0
1.68k stars 750 forks source link

library is not supporting utf-8/other encodings. #602

Open Pionell opened 4 years ago

Pionell commented 4 years ago

Hello, I'm struggling here.

I've tried loading custom font families like Roboto from google fonts, thinking it might be a Windows ANSI included fonts issue, but that didn't seem to have fixed my problem. I've tried multiple encodings, like: UTF-8, ISO-8859-10,ISO-8859-4,iso-8859-13,iso-8859-15 with such a setup:

$html2pdf = new Html2Pdf('P', 'A4', 'en',true,"UTF-8");

My content is simple for testing purposes. But it seems that the library is not accepting these characters: ąčęėįųū only š and ž

$html2pdf->writeHTML("<page>ąčęėįšųūž</page>");

ejs-ejs commented 4 years ago

Confirm. Fonts defaults to Helevica, just "ž" is visible. from the string "Aš čia nežinau ką įrašyti kad būtų" firefox_QJ6rEkeo4m

Html2PDF comes s a part of ResourceSpace installation, the PDF is created in UTF-8 encoding with

` $html2pdf = new Html2Pdf($pdf_properties['orientation'], $pdf_properties['format'], $pdf_properties['language'], true, 'UTF-8', $pdf_properties['margins']);

$html2pdf->pdf->SetTitle($pdf_properties['title']); $html2pdf->pdf->SetAuthor($pdf_properties['author']); $html2pdf->pdf->SetSubject($pdf_properties['subject']); $html2pdf->setDefaultFont($pdf_properties['font']); `

UPDATE: As for me, it seems like default PDF font is not set to <page header> and <page footer> environments and thus defaults to ANSI-encoded Helvetica. I've created a PDF file, opened it in the Inkscape and my default PDF font, "DejaVu Sans" is used only outside these tags.

UPDATE II: examples/utf8.php will produce wrong PDF with this content:

<page>
<page_header>
ąčęįęėėūšž
ĄČĘĮĖĖŪŽŠ
</page_header>

яшертюиоп[]
асдфгхйкл;ь\
зжцвбнм,./

</page>

It will produce the correct PDF once <page_header> is removed. The same is true for <page_footer>

UPDATE III: For some reasons lines $this->parsingCss->initStyle(); are breaking the fonts in Html2Pdf.php, functions _tag_open_PAGE_HEADER_SUB() and _tag_open_PAGE_FOOTER_SUB(). When these lines removed, the code seems to parse in the ordinary way, the headers and the footers appears in all their glory.

Rapid0s commented 4 weeks ago

We stumbled upon the same issue today.

What you can do is to explicitly define the font using style attribute and it works as expected :)