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
251 views
in Technique[技术] by (71.8m points)

php - WriteHTML in mfpdf displays squares

Im using mpdf in codeigniter and the output display squares instead of korean language.

here is my code in writeHTML

$mpdf = new MpdfMpdf('zh-aCJK');

$mpdf->WriteHTML('<div style="line-height:140%;font-size:12px;margin-top:15px;margin-bottom:35px;"><span style="color:#666666;font-family:/*Some korean font*/;font-size:12px;background-color:#ffffff;">??? </span><span class="ex" style="color:#DC143C;font-family:/*Some korean font*/;font-size:28px;background-color:#ffffff;">? ???</span><span style="color:#666666;font-family:/*Some korean font*/;font-size:28px;background-color:#ffffff;"> ?? ?, </span></div>');

the output is

enter image description here

Thanks for the help.

question from:https://stackoverflow.com/questions/65887988/writehtml-in-mfpdf-displays-squares

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

1 Reply

0 votes
by (71.8m points)

Your constructor parameter is wrong, mPDF accepts an array. Set up your development environment to be "warned" about it with a Notice.

None of your specified fonts are included in mPDF distribution and therefore will not display unless you set them up correctly. Default replacement is DejavuSans which does not support korean as far as I can tell.

With multiple languages across a document, use

$mpdf = new MpdfMpdf(['autoLangToFont' => true]);

$mpdf->WriteHTML('<div style="line-height:140%;font-size:12px;margin-top:15px;margin-bottom:35px;">
    <span lang="zh">??? </span>
    <span lang="ko">? ???</span>,
    <span lang="ko"> ?? ?, </span>
</div>');

$mpdf->Output('example000.pdf', 'F');

(styles cleaned up.) This will select appropriate font families for given languages. Please note that I am just estimating language codes - I have little knowledge about CJK writing. In case all of your text is in korean, the zh-aCJK mode does not make sense in the first place.

If you want a custom font with a CJK support, follow the extensive documentation for custom fonts.

https://mpdf.github.io/fonts-languages/fonts-in-mpdf-7-x.html

Read more about overall configuration, including non-latin scripts at

https://mpdf.github.io/fonts-languages/choosing-a-configuration-v7-x.html


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

...