- Code: Select all
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setImageDirPath("Documents\\images\\");
InputStream is = new FileInputStream(new File("Documents\\sampleword.docx"));
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
PhysicalFonts.discoverPhysicalFonts();
Map<String, PhysicalFont> physicalFonts = PhysicalFonts.getPhysicalFonts();
Iterator<Entry<String, PhysicalFont>> availableFonts = physicalFonts.entrySet().iterator();
while(availableFonts.hasNext())
{
Entry<String, PhysicalFont> font = availableFonts.next();
String key = font.getKey();
PhysicalFont pFont = font.getValue();
System.out.println("Key is " + key + ";; Name " + pFont.getName());
}
Mapper fontMapper = new IdentityPlusMapper();
PhysicalFont font = PhysicalFonts.get("Arial Unicode MS");
fontMapper.put("Times New Roman", font);
fontMapper.put("Arial", font);
wordMLPackage.setFontMapper(fontMapper);
foSettings.setWmlPackage(wordMLPackage);
OutputStream pdfOutputStream = new FileOutputStream("Documents\\output.pdf");
System.out.println(foSettings.getSettings());
Docx4J.toFO(foSettings, pdfOutputStream, Docx4J.FLAG_EXPORT_PREFER_XSL);
the whitespaces are not preserved in the resulting pdf