Last active
December 24, 2015 09:39
-
-
Save settermjd/6778757 to your computer and use it in GitHub Desktop.
Handle Umlauts and other characters in DOMPDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$pdf = new DOMPDF(); | |
$pdf->load_html(utf8_decode($customtext)); |
utf8_decode()
isn't nice to your text unless your characters are already iso-8859-1 compatible. It's a lossy (and dumb) decode, meaning if PHP can't find a suitable replacement it will discard your characters (or replace with ?
... I don't remember which). Review the comments in the documentation.
If you're using dompdf v0.6.x you can encode your document with UTF-8, just be sure to supply the content type meta tag indicating the encoding (see the Unicode How-To). If you're using v0.5.x you should encode your document in iso-8859-1 to begin with.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was having trouble outputting them and found this to work. I uncovered it at http://www.dashinteractive.net/dompdf/index.php?v=1609697 (right at the end). Please be aware that this was tested with PDFLib as the PDF backend.