- Code: Select all
public boolean convert(WordprocessingMLPackage wMLP) throws Docx4JException {
// Font regex (optional)
// Set regex if you want to restrict to some defined subset of fonts
// Here we have to do this before calling createContent,
// since that discovers fonts
// String regex = null;
// Windows:
String regex = ".*(calibri|cour|arial|times|comic|georgia|impact|LSANS|pala|tahoma|trebuc|verdana|symbol|webdings|wingding).*";
PhysicalFonts.setRegex(regex);
// Document loading (required)
// Set up font mapper (optional)
Mapper fontMapper = new IdentityPlusMapper();
try {
wMLP.setFontMapper(fontMapper);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// .. example of mapping missing font Algerian to installed font
// Comic
// Sans MS
PhysicalFont font = PhysicalFonts.getPhysicalFonts().get(
"Times New Roman");
fontMapper.getFontMappings().put("Calibri", font);
// New code
FOSettings foSettings = Docx4J.createFOSettings();
if (saveFO) {
foSettings.setFoDumpFile(new java.io.File(DIR_OUT + inputfile + ".fo"));
}
foSettings.setWmlPackage(wMLP);
// exporter writes to an OutputStream.
try {
String outputFile = FilenameUtils.removeExtension(inputfile) + ".pdf";
OutputStream os = new java.io.FileOutputStream(DIR_OUT + outputFile);
// Don't care what type of exporter you use
Docx4J.toFO(foSettings, os, Docx4J.FLAG_NONE);
System.out.println("Saved " + DIR_OUT + outputFile);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// end new code
return false;
}
When I create a simple Word document using Word and docx4j programmatically, the Header information is truncated into the document body section during conversion.
This appears to only happen with docx4j 3.0.0.
I ran the online PDF conversion tool on the document header looks ok.
I ran the ConvertPDF sample code for docx4j 2.8 and the document header looks ok.
It appears only the latest version of docx4j 3.0.0 is causing the issue.
Enclosed are source doc and sample converted pdf documents.
Please advise
Thanks