Replies: 4   Views: 1201
Thai and japanese fonts
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by jeremie  · 31-03-2020 - 18:51

I'm trying to create PDF documents with Thai and Japanese fonts using transformDocument with libreoffice.

I read your excellent guide "Good practices when working with font families" a thousand times but I can't make it work.

In Thai, I get a document with blanks or squares instead of Thai characters. Is there a default font that I can use for Thai?

In Japanese, I get a PDF with always the same font, no matter what font I set. I can't even know what this font is. It's not in my Linux installed fonts. Where can I find it and change it?


Posted by admin  · 01-04-2020 - 07:49


LibreOffice, OpenOffice and MS Word uses the fonts available in the OS. If some font is not available, they try to use the most similar one (if any available).

There're many free fonts available to be installed and used, and also many closed fonts that require purchasing them. We recommend installing as many of them as needed (even all available fonts in the Linux distribution you are using), for example, Debian includes fonts-thai-tlwg ( and many other fonts. On you can find a very good description of many available fonts in Linux.

Using Indexer you can get the font name used in a DOCX. And you can also embed fonts in a DOCX if any is not available in the OS, the embedded fonts are used by LibreOffice, OpenOffice and MS Word as well: (Adding new fonts to a DOCX section).


Posted by jeremie  · 01-04-2020 - 14:12

Thank you for your detailed answer.

Can transformDocument use embedded fonts?

Posted by jeremie  · 01-04-2020 - 17:08

So I tested transformDocument with an embedded font. It works fine when using "replaceVariableByText" but it doesn't work when using "replaceVariableByHTML".

In the code below, "Template.docx" is a template with embedded font and only one variable named $hello$ in the template. The embedded font is not installed in our Linux server.

Here is a code that works:

$docx = new CreateDocxFromTemplate('Template.docx');
$docx->replaceVariableByText(array('hello' => 'Hello world'));
$docx->transformDocument('TestTransformDocument.docx', 'TestTransformDocument.pdf', 'libreoffice');

And here is a code that doesn't work:

$docx = new CreateDocxFromTemplate('Template.docx');
$docx->replaceVariableByHTML('hello', 'block', 'Hello world');
$docx->transformDocument('TestTransformDocument.docx', 'TestTransformDocument.pdf', 'libreoffice');

In the first case, with "replaceVariableByText", we get a document with the text 'Hello world' in the embedded font (even though the font is not installed in our server).

In the first case, with "replaceVariableByHTML", we get a document with the text 'Hello world' in another default font, which is not the embedded font.

What are we doing wrong?

Posted by admin  · 01-04-2020 - 18:02


Embedded fonts are fonts included in the DOCX file, not the default font: . LibreOffice works with embedded fonts too.

replaceVariableByText keeps the font-family used by the placehoder in the template unless the whole paragraph is replaced (type option of the method). replaceVariableByHTML doesn't keep the font-family of the placeholder, it adds a default font-family, so you need to set font-family to use a custom one.

phpdocx 10 added the stylesReplacementType option to keep existing placeholder pPr and rPr styles such as font sizes, font families and others when transforming HTML.