I'm having successful html-to-pdf conversions, but not with special characters.
Below is just a special character I'm trying to display, which displays in browsers on my Mac, when I put it simply inside an html document. (but not on my windows box)
<?php
require_once("../dompdf_config.inc.php");
$html = '€';
$dompdf = new DOMPDF(); $html = iconv('UTF-8','Windows-1250',$html);
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("contract.pdf");
exit(0);
?>
I keep getting a "?" (question mark) when the pdf is rendered. I know there's been lots of issues documented with regards to special characters, but I thought I'd give this a try, with the code I'm actually using.
If DomPdf isn't a recommended html-to-pdf conversion tool, I'll take any other recommendations!
Anything prior to 0.6.x has limited support for characters outside iso-8859-1 encoding. The Euro is supported in 0.5.x by using the appropriate Windows ANSI character code (
€
), but otherwise you have to jump through some PDF encoding hoops.The 0.6.0 release has better support for "special" characters. The default encoding is based on Windows ANSI (one of the few recognized by the PDF 1.3 spec). You can enable better character support by loading a Unicode-based font and enabling Unicode in dompdf and specifying that encoding in your document.
The following should work in dompdf 0.6.0 or greater:
(or to be lazy just use the euro entity
€
in your test)There is a document outlining the steps needed to enable Unicode support in DOMPDF. Plus read this answer for an overview of how to load fonts.
I have experienced problems with DOMPDF when converting an UTF-8 html page. I simply solved the problem by adding
Between < head > tag. Maybe it could be an alternative if you set it with your encoding type.
IMPORTANT NOTE from comments below: don't use stream() and output() methods on the same pdf instance. If you do this wont work.
You must use another character set. For example dejavu Sans Mono. Add your code
i told in this video about this also.
DOMPDF Latin Turkish (Türkçe) char problem, my solution %100 Work.
Server requirenment control:
Char 'dejavu sans mono' (Turkish support) OR:
Step 1: dompdf_config.inc.php edit to
Step 2: lib/fonts/dompdf_font_family_cache.dist.php edit to add code:
Step 3: doqnload font files to copy lib/fonts folder. Download font files Link http://www.2shared.com/file/k6hdky_b/fonts.html
Step 4: Your code Edit example:
End Finish PDF > example http://limitsizbilgi.com/pdf/dompdf-chartest.pdf
after trying all solutions on the net. I could solve without modifying the dompdf. the problem was on the html content. I just had to add the correct and appropriate HTML structure and setting the font of course . Tested on v0.6.0 and v0.6.1. here I leave the code