javaapache-fopdocx4j

Missing border around image when converting a docx file to pdf with docx4j


I'm using docx4j for simple docx templating work. I replace some text which works fine. The template also has an image with a border (Word: Picture tools -> Format -> Picture Border). Exporting to PDF works fine except that the border around the picture is missing. Is this the expected behaviour or I'm something missing in the pdf exporting settings or similar?

InputStream templateInputStream = this.getClass().getClassLoader().getResourceAsStream(TEMPLATE_NAME);

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(templateInputStream);
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();

VariablePrepare.prepare(wordMLPackage);

HashMap<String, String> variables = new HashMap<>();
variables.put("firstName", "Stefan");
variables.put("lastName", "Ziegler");
variables.put("salutation", "Herr");
variables.put("message", "Top of the Pops.");

documentPart.variableReplace(variables);

String outputfilepath = "/tmp/message.pdf";
FileOutputStream os = new FileOutputStream(outputfilepath);

Docx4J.toPDF(wordMLPackage,os);
os.flush();
os.close();


Solution

  • Expected behaviour if you are using export-FO. For alternative approaches, please see https://github.com/plutext/docx4j/tree/VERSION_11_4_10/docx4j-export-fo#readme

    Note: as at the time of writing, some changes are needed to https://github.com/plutext/java-docx-to-pdf-using-Microsoft-Graph on account of recent changes by Microsoft.