Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
922 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...