Skip to content

Instantly share code, notes, and snippets.

@settermjd
Last active December 24, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save settermjd/6778757 to your computer and use it in GitHub Desktop.
Save settermjd/6778757 to your computer and use it in GitHub Desktop.
Handle Umlauts and other characters in DOMPDF
$pdf = new DOMPDF();
$pdf->load_html(utf8_decode($customtext));
@settermjd
Copy link
Author

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.

@bsweeney
Copy link

bsweeney commented Oct 2, 2013

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