Prestashop: PDF invoice uses a different font depending on the language (French vs. English)

2.1k views Asked by At

Using Prestashop 1.5.5.0 for a bilingual store (English/French), I noticed that the PDF generated for the invoice had a noticeably different presentation depending if it was generated in English or in French.

The most noticeable differences are:

  • the font family used is different in English: the letters are sensibly larger (esp. in lower case), and of different shapes; I was not able to identify which font it is, however.
  • in English, every text element that is supposed to be bold appears with a normal font-weight (not bold, then); my guess is that the font-family that is used in English doesn't have a bold variant.

Here's a comparison of both fonts (French left, English right):

font comparison

Just to be sure, I made a very small change to the invoice.tpl file (I just added a simple dot somewhere in the content), and then I re-downloaded the PDF invoice in both languages: the change appeared in both languages. So both languages use the same TPL file. Yet they do not use the same font-family.

My question is: where should I look in order to correct that?
I can't find any font-family declaration in the TPL files, and I don't understand why English would use a different font-family than French.

Edit: By the way, if somebody is able to identify (with reasonable certainty) which font is used in English (see image above), please let me know in the comments, as I may be able to use that information to search through all the files of the site and maybe get an idea where this problem comes from?...

2

There are 2 answers

4
Kurt Pfeifle On

"By the way, if somebody is able to identify (with reasonable certainty) which font is used in English (see image above), please let me know"

You can identify with (almost) absolute certainty which fonts are used in both types of PDF files yourself. Just run this command:

pdffonts -f 1 -l 5 pdffile.pdf

(This shows you all fonts used from page 1 to page 5 of the PDF, in case you are not interested in the other pages...)

If you get a no for both columns, emb as well as sub, then the font is not embedded in the PDF, and your PDF viewer is free to use any suitable substitute font it deems appropriate.

pdffonts is available for Linux, Unix, Mac OSX and Windows.

5
s427 On

So, I just discovered that you can get a list of the fonts used in the PDF document through Acrobat itself (menu File > Properties, Fonts tab).

This has allowed me to identify the font used in the English invoices PDF: DejaVuSans. I ran a search on this term across all the files of the site, and I found my culprit in classes/pdf/PDFGenerator.php, which has this variable defined:

public $font_by_lang = array(
    'ja' => 'cid0jp',
    'bg' => 'freeserif',
    'ru' => 'freeserif',
    'uk' => 'freeserif',
    'mk' => 'freeserif',
    'el' => 'freeserif',
    'en' => 'dejavusans',
    'vn' => 'dejavusans',
    'pl' => 'dejavusans',
    'ar' => 'dejavusans',
    'fa' => 'dejavusans',
    'ur' => 'dejavusans',
    'az' => 'dejavusans',
    'ca' => 'dejavusans',
    'gl' => 'dejavusans',
    'hr' => 'dejavusans',
    'sr' => 'dejavusans',
    'si' => 'dejavusans',
    'cs' => 'dejavusans',
    'sk' => 'dejavusans',
    'ka' => 'dejavusans',
    'he' => 'dejavusans',
    'lo' => 'dejavusans',
    'lv' => 'dejavusans',
    'tr' => 'dejavusans',
    'ko' => 'cid0kr',
    'zh' => 'cid0cs',
    'tw' => 'cid0cs',
    'th' => 'freeserif'
    );

Disabling (commenting) the 'en' => 'dejavusans', line did indeed solve the problem.

It's a bit of a hack obviously, so if anyone has information as to why English is in that list (and not French), and if there is a better way of handling this issue, I'm all ears. :)