Display unicode symbols (heart, diamond, etc.) in FPDF

五迷三道 提交于 2019-12-13 05:16:59

问题


I am currently using FPDF to generate PDFs in PHP. Occasionally, these PDFs must include unicode icons like hearts, diamonds, spades, etc. Here's an example:

"This is a string ♡♡"

However, I cannot get those symbols to display. I've tried mb_convert_encoding, iconv, changing the font and none of them are giving me the result I need. Chinese, Japanese and Korean text are all displaying without issue; the problem seems to be related only to symbols.

Any ideas of how to display these in FPDF? Thanks.


回答1:


I'm using TCPDF for generating PDF files

 $UnicodeString='♡♡♡♡♡♡♡♡♡♡';
 $fileNameHere='UnicodeFile.pdf';

 $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
 $pdf->setFontSubsetting(true);
 $pdf->SetFont('dejavusans', '', 20, '', true);
 $pdf->AddPage();
 $pdf->writeHTMLCell(0, 0, '', '', $UnicodeString, 0, 1, 0, true, 'L', true);
 $pdf->Output($fileNameHere,'F');



回答2:


I actually just ended up porting all the FPDF-dependent code to mPDF. Took a while, but ultimately better than trying to hack something together that works with FPDFs limited capabilities.

Thanks for the responses.



来源:https://stackoverflow.com/questions/25930770/display-unicode-symbols-heart-diamond-etc-in-fpdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!