Using Docx4j(3.2.0), tried to generate PDF from docx using 'Docx4J.toFO'.
Arabic characters are missing in PDF.
Code Snippet:
- Code: Select all
private static void createTestPDF() throws Exception{
FOSettings foSettings = Docx4J.createFOSettings();
InputStream is = new FileInputStream(new File("testarabic.docx"));
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
//Print all available physical fonts
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);
wordMLPackage.setFontMapper(fontMapper);
foSettings.setWmlPackage(wordMLPackage);
OutputStream pdfOutputStream = new FileOutputStream("testarabic.pdf");
System.out.println(foSettings.getSettings());
Docx4J.toFO(foSettings, pdfOutputStream, Docx4J.FLAG_EXPORT_PREFER_XSL);
System.out.println(" Done !!!!");
}
Attached documents.
Environment : Windows 7
Java Version: 1.6
Kindly help.
Thanks.