2
votes

I know that TCPDF supports special characters and multiple languages. I have tried all the provided fonts. I want to generate the PDF in UTF-8. I know that the included font 'freeserif' for sure includes the character in question. "•"

Here is my current constructor call:

$pdf=new MYPDF('P', 'mm', 'Letter', true, 'UTF-8', false);

Here is an example of the character being generated:

$this->Cell(80,6.35,"• $POST[reportTitle]",0,0,'L',true);

I have also tried replacing the character with its html code:

•

1
Is $POST[reportTitle] actually $_POST[reportTitle]? I don't know whether it is possible to inject stuff into a PDF (JavaScript?) but if you're taking user input, might be worth ensuring it is untainted before you put it in. - halfer
Nope, $POST is an array I built myself, which contains the $_POST array a page back. It is not posting to the PDF, I pass it in the $_SESSION. Sorry for the confusion, I didn't think to point that out! - Base Desire
Ah cool. Should be $POST['reportTitle'] to avoid warnings, however. - halfer
I agree, however sometimes it confuses PHP when its in parameters. Not sure why. - Base Desire
Try wrapping it all in braces (I would anyway, tbh): "• {$POST['reportTitle']}" - the issue may be confusion between the outer speech marks and the inner apostrophes - make sure the inner set are apostrophes and not speech marks. - halfer

1 Answers

2
votes

As seen here :

Set the $unicode parameter on the TCPDF constructor to false and the $encoding parameter to 'ISO-8859-1' or some other character map.

This will help you:

Default for UTF-8 unicode:

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

Example of constructor for European charset:

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'ISO-8859-1', false);