0

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.

haxie
  • 11
  • 3
  • 1
    Are you sure your font contains these characters? – Jongware Sep 20 '14 at 10:22
  • It is very easy and quite possible! tFPDF, a branch of the FPDF project, allows you to use UTF-8 in PDF's, take a look at my answer here: https://stackoverflow.com/a/56429391/2430549 – HoldOffHunger Jun 04 '19 at 16:27

2 Answers2

0

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');
Paramore
  • 1,313
  • 2
  • 19
  • 37
  • Thanks for this, I ended up going with mPDF, but I'm sure TCPDF would've worked well, too. – haxie Sep 23 '14 at 06:22
  • You are welcome. As far as I know mPDF has stopped development. Last release was 31/12/13. I recommend using TCPDF. It is much more stable. http://www.techwars.io/fight/tcpdf/mpdf/ – Paramore Sep 23 '14 at 11:19
0

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.

haxie
  • 11
  • 3
  • 1
    It's not really a question of "FPDF's limited capabilities." If your font does not contain heart symbols, you will not get the expected symbol, no matter what software you use. – HoldOffHunger Jun 04 '19 at 16:28