First of all let me thank you for this extremely useful library.
But I am having a little problem related to fonts when the docx is converted to pdf and also when docx is converted to XHTML. It fails to recognize any font and defaults all to a single font. I am sure I am missing something. Only if you can look at it and guide me.
I am using windows 7 box right now, but ultimately the code would be migrated to linux box in production.
I am attaching the log output (which is in zipped format due to max file upload restriction) for pdf conversion, the code used for conversion and both the docx file as well the result pdf.
code :
- Code: Select all
static void convertDocxToPdfViaDocx4j(String inputDocx, String destPdf) throws Exception {
String regex = null;
regex=".*(calibri|cour|arial|times|comic|georgia|impact|LSANS|pala|tahoma|trebuc|verdana|symbol|webdings|wingding).*";
PhysicalFonts.setRegex(regex);
File docxFile = new File(inputDocx);
WordprocessingMLPackage wordMLPackage = Docx4J.load(docxFile);
// Set up font mapper
Mapper fontMapper = new IdentityPlusMapper();
//fontMapper.getFontMappings().putAll(PhysicalFonts.getPhysicalFonts());
wordMLPackage.setFontMapper(fontMapper);
FOSettings foSettings = Docx4J.createFOSettings();
//to save fo dump
//foSettings.setFoDumpFile(new java.io.File(destFilePath + ".fo"));
foSettings.setWmlPackage(wordMLPackage);
//TODOd
//os = new java.io.FileOutputStream("D://yeah.pdf");
OutputStream os = new java.io.FileOutputStream(destPdf);//ByteArrayOutputStream();
Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
os.close();
}