Magento2: Magento 2.1.6 - Invoice PDF doesn't support Thai

Created on 17 May 2017  路  15Comments  路  Source: magento/magento2

Preconditions

  1. Magento CE 2.1.6

Steps to reproduce

  1. In the admin, go to Sales > Orders
  2. Select one 'completed' order and select the action 'Print Invoices' (any of the Print... actions actually)

Expected result

  1. Be able to read Thai names and Thai adresses in Thai alphabet

Actual result

  1. Thai letters are replaced by squares. Thai baht currency symbol is also unreadable.
    invoice2017-05-17_11-19-09.pdf
Sales Translation Fixed in 2.1.x Fixed in 2.2.x Fixed in 2.3.x Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x bug report

Most helpful comment

@magento-engcom-team Please check same for arabic too as I am facing same issue.

All 15 comments

Internal ticket MAGETWO-70209 was created;

Any suggestion for a temporary fix?

@jsdupuis

Here is very dirty workaround / backup all file before doing these steps. ->

  1. Get Thai font and upload to /lib/web/fonts (Font-version must be table v3, since the library can't parse table v4 font.)
  2. Change font-location to uploaded fonts' location in /vendor/magento/module-sales/Model/Order/Pdf/AbstractPdf.php
   function _setFontRegular
   function _setFontBold
   function _setFontItalic

** you might need to adjust font size according to your font, finding "setFontSize"

  1. Modify $drawingString in same file :: /vendor/magento/module-sales/Model/Order/Pdf/AbstractPdf.php
        $drawingString = '"libiconv"' == ICONV_IMPL ? iconv(
            'UTF-8',
            'UTF-16BE//IGNORE',
            $string
        ) : @iconv(
            'UTF-8',
            'UTF-16BE',
            $string
        );

to

        $drawingString = mb_convert_encoding($string, "UTF-16BE", "UTF-8");

If you get the error about cannot convert MacRoman. then you might have to edit /vendor/magento/zendframework1/library/Zend/Pdf/FileParser.php and look for

function readStringMacRoman

replace

return iconv('MacRoman', $characterSet, $bytes);

with

return mb_convert_encoding($bytes, $characterSet, 'UTF-8');

PS. This is not appropriate way to deal with this issue. However LinLibertineFont contains no Thai-characters , and iconv lib can't properly convert MacRoman to UTF16BE (Used in thai font like TH Sarabun)

PS.2. This is very dirty fix. If your store is in EN/TH then it might work. But this might raise some errors if dealing with other char-encoding.

-------- BTW, Thai-font issue is in magento since 1.xx

I am using Magento 2.1.7 and facing same character issue when printing invoice of arabic order. Any update for solution ?
screenshot from 2017-09-14 11 48 14

@jsdupuis, thank you for your report.
We've created internal ticket(s) MAGETWO-70209 to track progress on the issue.

@magento-engcom-team Please check same for arabic too as I am facing same issue.

Hi @jsdupuis. Thank you for your report.
The issue has been fixed in magento/magento2#13016 by @rossmc in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.5 release.

great news , thanks every one

Hi @jsdupuis. Thank you for your report.
The issue has been fixed in magento/magento2#14711 by @rossmc in 2.1-develop branch
Related commit(s):

The fix will be available with the upcoming 2.1.15 release.

Hi @jsdupuis. Thank you for your report.
The issue has been fixed in magento/magento2#14710 by @rossmc in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

@magento-engcom-team
Hello,
https://github.com/magento/magento2/commit/abd7be087cebeae8109f8d998d24361cedb2d554

this fix is not enough to fix the problem. the characters become supported but. still the letters are not connected together.

letters not connected

After long investigation I found that zend pdf library doesn't support arabic language.
the solution for this is to use extension use another pdf library.
i found this extension uses another library and support arabic. you have to pay for it sorry didn't found free one. https://www.vnecoms.com/magento2-extensions/magento2-pdf-invoice-pro.html

@o0mohammed0o I have this error, did you suggest any solution except this one
https://www.vnecoms.com/magento2-extensions/magento2-pdf-invoice-pro.html

i am getting same font issues in order invoice print out from admin panel.
from customer panel its working perfectly. if any solution please put it here.

If anyone found solution for Arabic. Please let me know

Was this page helpful?
0 / 5 - 0 ratings