Search code examples
javapdfbox

PDFBox 2.0.17 Fonts on Linux


I am converting a page in a PDF document to bytes and then constructing an image out of it.

On Windows, the image is constructed fine. On Linux, the letters on the image look smudged (overlap each other)

In the logs (weblogic), i see the following indicating the fonts required are missing on Linux.

<Dec 3, 2019 11:06:35 PM EST> <Warning> <org.apache.pdfbox.pdmodel.font.PDType1Font> <BEA-000000> <Using fallback font LiberationSans for Helvetica-Bold>
<Dec 3, 2019 11:06:35 PM EST> <Warning> <org.apache.pdfbox.pdmodel.font.PDType1Font> <BEA-000000> <Using fallback font LiberationSans for Times-Roman>
<Dec 3, 2019 11:06:35 PM EST> <Warning> <org.apache.pdfbox.pdmodel.font.PDType1Font> <BEA-000000> <Using fallback font LiberationSans for Times-Bold>
<Dec 3, 2019 11:06:35 PM EST> <Warning> <org.apache.pdfbox.pdmodel.font.PDType1Font> <BEA-000000> <Using fallback font LiberationSans for Times-Italic>
<Dec 3, 2019 11:06:35 PM EST> <Warning> <org.apache.pdfbox.pdmodel.font.PDType1Font> <BEA-000000> <Using fallback font LiberationSans for Helvetica>

How can supply the missing fonts on Linux? I see references to using a properties file (PDFBox_External_Fonts.properties) on versions before 2. What can i do on pdfbox version 2.0.17? I am unable to find any documentation on how to proceed.


Solution

  • Tilman Hausherr from the PDFBox users mailing list helped out.

    Copying the required fonts to the {home}/.fonts folder helped resolve my issue. The PDFBox code looks in the following directories for fonts.

    protected String[] getSearchableDirectories()
    {
         return new String[] { System.getProperty("user.home") + "/.fonts", // user
                 "/usr/local/fonts", // local
                 "/usr/local/share/fonts", // local shared
                 "/usr/share/fonts", // system
                 "/usr/X11R6/lib/X11/fonts" // X
         };
     }