Monday, May 16, 2011

TCPDF and True Type Unicode Fonts

Ok, so todays aim was to fix a problem with embedded fonts in PDFs generated by TCPDF.

The symptoms were:
  • An error on my computer "Cannot extract the embedded font" when printing.
  • A customer got a strange error and couldn't print the PDF at all (I can't find the error message sorry).
  • When viewing on the iPhone, parts of the document were missing.
We'd created the font files by going straight from the font in C:\Windows\Fonts using the instructions at http://www.tcpdf.org/fonts.php (.ufm files), so for TTF Unicode.

The solution was:

  1. Install this: http://ttf2pt1.sourceforge.net/ in Ubuntu it's as easy as apt-get install ttf2pt1
  2. Copy the windows ttf files to the linux box, change the filenames to all lower case and no spaces.
  3. Go to the tcpdf/fonts/utils directory.
  4. Put your lower case ttf files here.
  5. Run ttf2pt1 yourfontfile.ttf
  6. php makefont.php yourfontfile.ttf yourfontfile.afm
  7. cp yourfontfile.php ..
  8. cp yourfontfile.z ..
  9. DONE!
This changes it to an ANSI ttf instead of a CID one. You can check out the fonts in the PDF document by opening a document and going File>Properties>Fonts. If you see the embedded fonts as anything other than True Type ansi, you've got a problem, try the steps again!

Now the files work perfectly on iPhone, and for printing. Problem solved.

5 comments:

  1. Hi have a converter for the converting from ttf and otf fonts for tcpdf

    http://fonts.snm-portal.com/

    ReplyDelete
  2. I didn't test it out, but that looks great.

    ReplyDelete
  3. The converter works perfect!
    The Windows process not work like Linux.
    Thanks at all!

    ReplyDelete
  4. Thank you! This post saved me a lot of time!!

    ReplyDelete