Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
927 views
in Technique[技术] by (71.8m points)

dompdf special characters

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 = '&#8364;';
$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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have experienced problems with DOMPDF when converting an UTF-8 html page. I simply solved the problem by adding

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...