3

I am using Docx4J.toPDF(wordMLPackage, new FOS("path/to/file.pdf")) in order to convert a ".docx" file to ".pdf". Although the conversion is happening fine but the original document had Calibri font and the resultant pdf has Arial. Is there a way to set the font while doing this conversion.

It would be better if you could give some link to how font properties can be set in general like font size, font family etc, if there is facility for that.

I searched online but could not find any help on this. Waiting for your responses. Thanks!

Aditya Bahuguna
  • 647
  • 7
  • 22

1 Answers1

1

I think that you will have to embend the Calibiri font (file) into the PDF. I am using Calibri in generated PDFs as well and this is what i had to do. I was using PDFe

I dont know how how to do this in docx4j, but in case of iText(that I am using) I had to register the font like this

    FontFactory.registerDirectory("./resources/fonts/", true);
    com.itextpdf.text.Font iFont = FontFactory.getFont(font, getEncodingForFont(font), true);

and after this, iFont was automaticly embended into PDF so it can be displayed correctly on systems that does not have Calibri installed.

This may be related to your issue http://www.docx4java.org/forums/docx-java-f6/embedded-fonts-not-used-in-pdf-conversion-t1137.html

And also there seems to be something into the canse on SO already: How to change font encoding when converting docx -> pdf with docx4j?

Community
  • 1
  • 1
Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • +1 Thanks for quick response. I am not sure if it happens similary in docx4j as in iText but the link u provided seem to have some information. On it!. – Aditya Bahuguna May 09 '16 at 06:12
  • 1
    @AdityaBahuguna also check the second link to SO that i have added. There is a straightforward way how to apply propert font into PDF during conversion. – Antoniossss May 09 '16 at 06:13
  • I will mark your answer accepted as the info u gave is correct. Quoting from the Docx4J documentation "When docx4j is used to create a PDF, it can only use fonts which are available to it.These fonts come from 2 sources: 1) those installed on the computer 2)those embedded in the document" - So i think I will embed it, for portability. Rest should work automatically because the method I am using is a Facade to pdf conversion and the fallback options must be there. – Aditya Bahuguna May 09 '16 at 06:26
  • @AdityaBahuguna yes, embending is the way to go, because if you would try to open your document on system that does not have `Calibri` installed, text in PDF will fallback to the default font. Due to that fact the same PDF can look different on 2 different machines - thus the embending makes it realy "Portable Document Format" :) I am glad I could help. – Antoniossss May 09 '16 at 06:46