PHP – dompdf UTF-8 decode problem

The dompdf is a PHP library which help you to convert HTML into a PDF file. Actually i haven’t tried to implement it by myself but recently, i followed an project which used the dompdf and there is a UTF-8 decoding issue for special character like an Apostrophe.

As i have mentioned, dompdf convert a HTML into a PDF, therefore, the UTF-8 problem can be solved by setting the charset meta as follow

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
...

 

The above modification can print the Apostrophe correctly in my case, but for other special characters, you may need to use the utf8_decode() to solve the problem.

Done =)

Reference:

6 thoughts on “PHP – dompdf UTF-8 decode problem”

  1. In the 0.6.0 releasea DOMPDF will attempt to decipher your document encoding by looking for the meta tag you cited. If DOMPDF finds the tag it should be able to correctly handle a variety of character encodings (depending on your system setup … namely the availability of the mbstring extension).

    Glad you were able to solve your problem.

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.