1

I have a wordpress plugin which generates PDF receipts using TCPDF. Although the greek text shows OK with DejaVuSans, it is showing questionmarks (???) when the font is set to Helvetica. It is more of a cosmetic problem since DejaVuSans is kinda ugly and it doesn't seem to support italics or strong styles. I checked the contents of the tcpdf's fonts folder and I can see that helvetica font is indeed installed.

Any ideas and/or suggestions are welcome.

Manos Krokos
  • 113
  • 1
  • 3
  • 12

1 Answers1

2

This answer is correct to the best of my knowledge however, I am not an expert on the subject. Also, I am referring to the "old version" when mentioning TCPDF, not the new version that is under development.

Why this occurs

Helvetica is one of the standard 14 or core fonts that should be compatible with most PDF readers. This means that the fonts can usually be used in a PDF without having to embed it in the PDF document. You can see a list of the core fonts in the TCPDF documentation. The "helvetica.php" file in the TCPDF fonts directory is not a copy of the Helvetica font. The file is only a description of the font as described here.

The downside of using these core fonts is that you are relying on the version of the font included with each user's PDF reader or installed on their systems. According to this Wikipedia article, some PDF readers will substitute similar fonts and these will often have different character sets. I assume this is done to save money on licensing fees for fonts that are not open source.

In your situation, I am guessing that your PDF reader is not using the same font that is installed elsewhere on your computer. It is likely using a substitute font that is not the Helvetica® font designed by the Linotype Design Studio.

Solution

I have encountered a similar situation in the past and solved it by embedding a free open source font in the document. This included creating custom characters that would never be installed on a user's computer. PDF readers will use the font embedded in the document to render the PDF. The embedding process requires that you first convert the font’s TTF file using the TCPDF addTTFfont() method before generating the document with TCPDF.

Converting and embedding fonts is discussed in the TCPDF documentation and in this related answer about font conversion: https://stackoverflow.com/a/19394545/9356981

Licensing fonts

Licensing and embedding the Helvetica font is one option, but this could get very expensive. You may want to search for open source fonts on services such as https://fonts.google.com which includes a Greek character search filter.

Adam Moller
  • 903
  • 8
  • 11
  • Although it would be interesting to investigate this further, it would not provide a solution. Even if I find and install a Helvetica font compatible with the TCPDF one, not all site users will bother. So I guess I am stuck with DejaVuSans. – Manos Krokos Feb 19 '18 at 10:20
  • 1
    A bit more exactly: According to ISO 32000-1 all PDF Readers must support the standard 14 fonts (*These fonts, or their font metrics and suitable substitution fonts, shall be available to the conforming reader.*) but only for Latin encodings (*"Latin Character Set and Encodings", describes the entire character set for the Adobe standard Latin-text fonts. This character set shall be supported by the Times, Helvetica, and Courier font families, which are among the standard 14 predefined fonts*). – mkl Feb 19 '18 at 16:00
  • @Manos Embedding a font in the document will allow everyone to view the PDF and see the characters as you intended, without installing it on their systems. The non-standard DejaVuSans font that comes with TCPDF has already been converted and is embedded in the document each time you use it. Developers have included the _addTTFfont()_ method, so you can do the same with any font available in the TTF format. I have edited my answer with some additional information about finding and converting a font that works best for your purpose. – Adam Moller Feb 19 '18 at 16:08