4

I use PHP and TCPDF to generate online invoices encoded in utf8. I've created font definition files following the tutorial on the tcpdf website using PT-sans .ttf file.

Generated pdf files look fine (accents are displayed correctly) when opened with Adobe Reader. But as soon as you open the pdf file with Adobe Illustrator, you'll see a mix of normal ascii characters and missing characters signs. When opened as attachment in the gmail preview, no text is displayed at all, just images will show up.

I also get unconsistent behavior with Foxit reader. It was ok on one computer (with font installed), but corrupted on another (without the font installed).

Illustrator (on the left) and Foxit reader printscreen: http://dl.dropbox.com/u/14647415/illustrator%20and%20foxit.jpg

Here is a copy of the corrupted file: http://dl.dropbox.com/u/14647415/2011040-3.pdf

PDF's size is ±200kB, so font seems to be embeded correctly.

This seems to happen with any utf8 font, embeded with procedure described on the tcpdf website. When I tried the core cid fonts, that came with the tcpdf library, accented characters were missing, or have been replaced with ?, but the overal layout and text were ok in Illustrator, too. Attached utf-8 fonts like Dejavusans are showing up corrupted, too.

I use 'UTF-8' as a param passed into tcpdf constructor.

class XTCPDF extends TCPDF {

function __construct(){
    parent::__construct('P', 'mm', 'A4', true, 'UTF-8', false);
    ...
}
...

}

Do you have any ideas on what could be causing this?

Thank you very much in advance.

p.

Peter Pech
  • 81
  • 1
  • 5

1 Answers1

4

Problem was obviously caused by TCPDF automatically subsetting the font. This caused problems with charset (characters were "shifted", '0' interpreted as 'A' etc.) in aplications other than Acrobat.

Solution to this is setting:

$pdf->setFontSubsetting(false);

and subsetting your font manually to reduce the resulting file size, based on charset you want to use.

franzlorenzon
  • 5,845
  • 6
  • 36
  • 58
Peter Pech
  • 81
  • 1
  • 5
  • I have a similar problem in that no text is rendered when viewing a TCPDF generated file in Google Docs. Setting font subsetting to false did not solve the issue for me. Does anyone else have any solutions? – Chris Harrison Sep 20 '12 at 15:13
  • see also http://dev.piwik.org/trac/ticket/2018 and https://discussions.apple.com/thread/3140086?start=0&tstart=0, you have to $pdf->addFont() and setFontSubsetting(false) – max4ever Nov 20 '12 at 14:39
  • Thanks. I was having the same problem and this saved my day. – bananaCute May 24 '19 at 03:27