using jodconverter from java jar wrapped in a windows service - font problem

771 views Asked by At

I have been using jodconverter library for converting Microsoft Word documents (*.doc) to PDF files on the backend server. The backend is a Spring Boot application running on an old Windows Server 2008 Enterprise. (jodconverter requires a version of Apache OpenOffice or Libre Office to be installed on this machine - I have an OpenOffice 4 installed there - simple default install, not running as a service - I haven't seen any problem with that)

A specific use case is to convert documents that contain text rendered with a specific font not present on the Windows machine (an IDAutomation barcode font - it is an OTF file) - I figured out that installing that font on the server would be the only necessary thing to get me going (right click over the font file -> choose Install - there are no other options), and things seemed to be that way.

Now, I was starting the backend from the command-line - and thought to wrap it into a Windows service, using NSSM. I got me a nice working service, running under Local System account - which seemed to work nicely.

Later it was pointed to me that the barcode font is no longer rendered during the DOC to PDF conversion. Indeed I switched back to command-line interactive version and the font appeared again. I understand that this is clearly an issue with the way I am installing that font and that under Local System account - or whatever - the font just cannot be accessed and a fallback font is used.

I tried to specify to run the service under a different account - specifically the one, with which I installed the font - but this didn't help.

Question a) - how do one installs a font so that it could be accessible by Local System account? It would be nice if I could do it avoiding having to log in as a local admin - although if this is the only way then I will pursue to do so - I've thought whether this quesiton would be more suitable on serverfault or superuser, but decided to ask it here because my original problem seems to be on an application programming level

Question b) - is there a log file where I could trace the actual error message that the right font is not found and that a substitute font is used?

Thanks

[edit: the contents of my pom.xml related to JODConverter version]:

<properties>        
   <jodconverter.version>4.3.0</jodconverter.version>
</properties> 
...
<dependencies>
...
    <dependency>
        <groupId>org.jodconverter</groupId>
        <artifactId>jodconverter-spring-boot-starter</artifactId>
        <version>${jodconverter.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jodconverter</groupId>
        <artifactId>jodconverter-local</artifactId>
        <version>${jodconverter.version}</version>
    </dependency>
</dependencies>
2

There are 2 answers

0
hello_earth On

I am sorry for all the fuss - it seems that the oldest and the wisest solution that has been working for all kinds of computer problems for ages - yes, the machine restart - worked. I don't know if it would have worked if I haven't tried the following, though:

I tried @sbraconnier suggestion, learning about user profiles that LibreOffice uses. In my case I am using Apache OpenOffice, but the instructions do not change. the problem still persisted.

Then I saw some other suggestions to refresh the fonts cache. There was an interesting tutorial about how to do this here. Namely, they suggest to first stop Windows Font Cache Service, then to go to c:\Windows\ServiceProfiles\LocalService\AppData\Local and delete directories and files related to FontCache (e.g. I had a file called FontCache-System.dat there) - then also to delete c:\Windows\System32\FNTCACHE.DAT (keeping a backup, I guess) and start Windows Font Cache Service again. I did that but to no avail. I also observed that the above files take a bit of time to get regenerated - I don't know if a machine restart is required for this - I saw that FontCache-System.dat got regenerated before restart, but FNTCACHE.DAT was there only after the restart.

Then I found a link about using a custom local folder for TrueType fonts here. They suggest that you can use a (global) custom folder that does not depend on what user profile is using it. This folder is {LibreOffice installation folder}\share\fonts\truetype - incidentally, this "share" folder mirrors the structure of the user/instance profile folder mentioned by @sbraconnier - I tried creating the truetype folder and copying there my OpenType OTF font, but again, to no avail.

My last try was to restart the machine - and the font somehow got recognized. I am not sure what exactly from the above steps helped - that's why I recounted them all. Thanks again to @sbraconnier

2
sbraconnier On

Maybe you could try to use the templateProfileDir option, which is available in the jodconverter-spring-boot-starter module.

I'm not an expert of LibreOffice per se, but if the installed font is part of the user profile, I think it would work to use this profile instead of letting LibreOffice create a new one.

From this example (I changed how it's set since you use spring-boot):

Here on my Windows, after settings LibreOffice to suit my needs using the GUI (I guess for you it would be to install the font), I copied the directory C:\Users\myUser\AppData\Roaming\LibreOffice\4 into C:\JodConverter\templateProfile (to act as a template profile directory that won't change) and set the templateProfileDir to this copy (in the application.yml file):

jodconverter:
  local:
    enabled: true
    template-profile-dir: C:/JodConverter/templateProfile