问题
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