I am writing a Java application which should convert a DOCX to a PDF file. Unfortunately, the output file ignores certain formats from the docx-file such as:
1. centered header image (jpg), output is left aligned
2. columns from docx are ignored, pdf writes text underneath
I am using these lines of code for conversion:
- Code: Select all
File pdffile = new File(temp+"/_"+FilenameUtils.removeExtension(file.getName())+".pdf");
OutputStream os = null;
WordprocessingMLPackage document = WordprocessingMLPackage.load(file);
Mapper fontMapper = new IdentityPlusMapper();
document.setFontMapper(fontMapper);
File folder = Systemkit.createRandomDirectory("tmp/files/");
FOSettings fo = Docx4J.createFOSettings();
fo.setFoDumpFile(new File(folder.getAbsolutePath()+"/"+"report.fo"));
fo.setWmlPackage(document);
os = new FileOutputStream(pdffile);
Docx4J.toFO(fo, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
Is there a possibility to handle these formats either by changing the input file or changing the pdf converter options?
Thanks for your help.