Forum


Replies: 3   Views: 81
Missing fonts using libreoffice as conversion plugin

Posted by miso  · 04-12-2024 - 11:15

Here is my code, simple and basic:

$filein = 'test.docx';
$fileout = 'test.pdf';

$docx = new CreateDocx();
$docx->transformDocument($filein , $fileout);


and with that the output PDF I get looks like this:

https://img001.prntscr.com/file/img001/iSURmMlLRhW65pCBoT5ZLg.jpeg

I don't understand what am I missing here.

The fonts in DOCX are Times New Roman, standard. Libreoffice is installed just fine on the server with all the fonts that come with it and then some. I even have msfonts installed in /usr/share/fonts/msttcore/, but somehow, when I run fc -list from the specific account I'm using this on, I only get this list of fonts available:

https://img001.prntscr.com/file/img001/Gac_rCM8TyaNin5uxiShug.jpeg

and when I run that fc -list as a root, I get 5 times as many more fonts showing.

Does that have anything to do with it?

How do we solve this issue?

Posted by admin  · 04-12-2024 - 11:29

Hello,

It seems LibreOffice doesn't have access to the available fonts. What version of LibreOffice are you using? how did you install LibreOffice? using the packages available on libreoffice.org or the distro repository?
Maybe you are using an old version of LibreOffice? Please install and try with the latest version available on libreoffice.org.

We recommend you refresh the available fonts by running (as detailed on https://www.phpdocx.com/documentation/cookbook/good-practices-with-fonts  Fonts in the conversion plugin section) :

fc-cache -fv

(https://askubuntu.com/questions/1022627/how-to-reload-fonts-in-libreoffice)

If you send the DOCX you are transforming to contact[at]phpdocx.com we'll do some tests or our servers. Also please send the PDF output you get in your server.

Regards.

Posted by miso  · 04-12-2024 - 15:19

We just installed it via "yum install libreoffice" and are on the version 7.1.8.1 10.

We also installed the latest one from libreoffice.org website too, according to these instructions:

https://wiki.documentfoundation.org/Documentation/Install/Linux

We followed all those font instructions as well before, over and over, but still, no luck. 

We had to use embedFont() function to add basic fonts like Arial, Times New Roman, Verdana, etc to get this working... but we shouldn't have to do this, right? Shouldn't those basic fonts be available right off the bat without embedding them into our documents?

Posted by admin  · 04-12-2024 - 16:44

Hello,

Although LibreOffice can read embedded fonts, it also reads fonts available in the fs.

There's some read access issue in the fonts installed in your OS. It seems LibreOffice can't read/access them. Please check the information available on the following pages:

https://ask.libreoffice.org/t/how-to-add-ttf-font-files-to-libreoffice-on-linux/13079/9

https://askubuntu.com/questions/32088/some-fonts-dont-appear-in-libreoffice

Maybe you need to copy the fonts to ~/.local/share/fonts or ~./fonts, and refresh the font cache by running:

sudo fc-cache -f -v

fc-cache -f -v

to clean the global font cache, the root font cache, and the user font cache.

Please check if the user that runs LibreOffice has access to the fonts folder, and if the font list displayed with:

fc -list

are available in the same folder or distinct folders. Maybe the fonts displayed when running this command as root use different folders than the ones available by LibreOffice.

Also please test the conversion using PHP CLI mode (instead of a web server):

$ sample.php

with root and a regular user, and check if the PDF displays the contents correctly.

As requested in our previous reply, please send the DOCX document and PDF output to contact[at]phpdocx.com.

Regards.