Japanese letters disappear in PDF

Hi,

I’m trying to make an invoice in Japanese but Japanese letters disappear when exporting in PDF.

It happens when I pick Japanese as a language for the corresponding client and manually type in Japanese letters, both on 1.5.9 and 2.0.0a1.

Any ideas?

Your problem with v1.5.9 may be the same reported in this topic,

https://community2.invoiceplane.com/t/topic/6745

Unfortunately, there is no reply from the user, so I do not know whether installing the additional font files solved the problem. Maybe you could try downloading and installing a suitable font.

Check the list of fonts distributed or compatible with mPDF here and download mPDF fonts from here.

Hi, thanks.

I’ve just downloaded Sun-ExtA and Sun-ExtB (which cover Japanese) from here and moved to /vendor/mpdf/mpdf/ttfonts/ but the letters are still missing.

Is this a correct way to install?

Yes, this is the folder mPDF searches for fonts.

Can you check the pdf file properties (e.g. in Acrobat Reader, File -> Properties -> Fonts tab) and confirm whether the Sun fonts are included in the pdf file?

In the meanwhile I will investigate how mPDF handles fonts when converting from html to pdf.

I have managed to include arabic and cjk characters thanks to the answers here. Briefly, to solve the problem:

  • Download the Sun-ExtA and Sun-ExtB fonts from mPDF site and copy them to ‘vendor/mpdf/mpdf/ttfonts/’.

  • Edit the file ‘vendor/mpdf/mpdf/scr/Config/ConfigVariables.php’ and in the “AUTOMATIC FONT SELECTION” section, set to true the variables ‘autoScriptToLang’ and ‘autoLangToFont’ as in,

      // AUTOMATIC FONT SELECTION
      // Based on script and/or language
      // mPDF 6.0 (similar to previously using function SetAutoFont() )
      // 'autoScriptToLang' => false,
      'autoScriptToLang' => true,
      'baseScript' => Ucdn::SCRIPT_LATIN,
      'autoVietnamese' => true,
      'autoArabic' => true,
      // mPDF 6.0 (similar to old useLang)
      // 'autoLangToFont' => false,
      'autoLangToFont' => true,
    

Beware that (as of now) the Sun-Ext fonts are not embedded in the resulting pdf file, and that displaying the japanese characters requires having a proper local font file available to substitute Sun-Ext fonts.

Thanks so much, now it’s showing all the letters correctly.

I couldn’t check the file properties because of the Acrobat Reader installer saying “initialization error”.

Do you mean that the PDF displays Japanese letters as long as my customer has any Japanese font installed on his/her computer?

Is there any way to embed Japanese fonts?

Thanks so much, now it’s showing all the letters correctly.

Good to know it’s working

I couldn’t check the file properties because of the Acrobat Reader installer saying “initialization error”.

Check those pages, they may help you to install Acrobat Reader,

Do you mean that the PDF displays Japanese letters as long as my customer has any Japanese font installed on his/her computer?

That’s right, and this is the (recommended?) solution according to the mPDF manual. The font files are at the end of the Adobe’s page, look for the table under “Add ons”.

Is there any way to embed Japanese fonts?

I am investigating this possibility. As of now, the proposed changes to the configuration file cause the XB Riyaz fonts to be embedded in the pdf file, while the Sun-Ext* fonts are not. Thus, there must be another configuration option involved that I haven’t found yet (it is a quite long list).

For what it’s worth (for instance for similar future questions),

  • the fonts used (aka required) for each language are set in the file ‘vendor/mpdf/mpdf/scr/Language/LanguageToFont.php’, and
  • the correspondence between the value of the ‘$unifont’ variable and the actual font files can be found in the file ‘vendor/mpdf/mpdf/src/Config/FontVariables.php’

No matter what options I have tried, I haven’t managed to make mPDF to embed the Sun-Ext* fonts or a subset of it in the pdf file. I only managed to get the font embedded by adding the ‘sun-extb’ value to the ‘font-family’ property in the ‘template.css’ file, but then only the Japanese characters were displayed and all other text was lost, and I presume that’s not what you wanted.

A solution that may work, but I haven’t tested, would be: to create a custom field for the text in Japanese, and then modify a copy of the pdf template to display the custom field using the Japanese font as explained here. The

Another alternative is to process the pdf with a software that embeds the fonts. For instance, you could use the ‘pdftocairo’ tool of the Poppler library (Windows version here) as in,

> pdftocairo -pdf 2018-09-02_Invoice_14.pdf test.pdf

I have tested the tool on GNU/Linux and all fonts where embedded in the new pdf file, which surprisingly was smaller (22K) than the original file (49K) in spite of containing all used fonts,

$ pdffonts test.pdf 
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
ZLSITS+DejaVuSansCondensed-Bold      TrueType          WinAnsi          yes yes yes      5  0
VYUNIJ+DejaVuSansCondensed           TrueType          WinAnsi          yes yes yes      6  0
NRPACB+XBRiyaz                       CID TrueType      Identity-H       yes yes yes      7  0
GKCFTT+XBRiyaz                       TrueType          WinAnsi          yes yes yes      8  0
SOYXSZ+DroidSansFallback             CID TrueType      Identity-H       yes yes yes      9  0