Free Support Forum - groupdocs.com

How to setup font directory for PDF conversion in Java

Hi Groupdocs,

I am attempting to leverage the Java document conversion library, and I’m running into an issue setting the correct font of the PDF. This is how I’m calling the conversion API:

public FileInputStream convertWordInputStreamToPdf(InputStream wordInputStream) {
    NoteLoadOptions noteLoadOptions = new NoteLoadOptions();

    noteLoadOptions.setDefaultFont("./fonts/TimesNewRoman.ttf");

    Converter converter = new Converter(wordInputStream, noteLoadOptions);
    PdfConvertOptions options = new PdfConvertOptions();
    String pdfFilePath = TempFileSystem.getTempPath(PDF_FILE_TYPE);
    converter.convert(pdfFilePath, options);

Note: this only outputs the wrong font when I run in my docker container. I have mounted the ./fonts directory in the container, however, and have validated that that mount works correctly when setting setting fonts for the Comparison api.

I’ve uploaded an example pdf output of the above code
test-convert-docx-to-pdf-times-docker.pdf (29.0 KB)

Can someone assist me with this? Am I setting the font correctly?

Thanks,
Jordan

@jobryan

Could you please share the problematic file and also specify the GroupDocs.Conversion for Java API version (e.g. 20.10, 21.1) that you are evaluating.

The mounted font directory works well for GroupDocs.Comparison but gives wrong output for Conversion API, right?

Hi Atir,

Apologies for the delay.

I’ve attached the files to this post.

I am using Groupdocs Conversion 20.10.3

Yes, that’s correct.

Jordan

.ExampleConvert.zip (151.9 KB)

1 Like

@jobryan

Could you please also share the docker image? Or if you have placed it on some source control (e.g. GitHub), share the URL.

Hi Atir, I’ve attached the Dockerfile to this post.

docker.zip (812 Bytes)

@jobryan

We are investigating this issue with ticket ID CONVERSIONJAVA-1259. You’ll be notified in case of any update.