Page 1 of 1

PDF Conversion on Unix server

PostPosted: Tue Jul 01, 2014 11:37 am
by todd
We are seeing some formatting issues while converting documents on a Unix environment. Windows environment seems to be fine, however the same pdf logic conversion running on our Unix version seems to have some issues with font formatting.
We do not see any bold letting and some of the index numbering is in a bigger font.
We can save a docx4j created document as a pdf using Word and it all looks good.
When we run our application on Windows to convert the docx document to PDF it looks good.
When we run our application on Unix to convert the docx document to PDF, we have the issues.
Is there some special font mapping we need to address for Unix system?
Using docx4j latest nightly build.
Using Plutext-Enterprise.jar 3.1.0
Windows 7
Unix JDK Oracle 1.6.0_20

The PDF conversion logic is as follows.

// 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 {
wordMLPackage.setFontMapper(fontMapper);
} catch (Exception e) {
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);

String tempFilename = DIR_OUT + "ConvertDocumentToPDF-" + DocxUtil.getFormattedDateTextForFileName();
FOSettings foSettings = Docx4J.createFOSettings();
if (saveFO) {
String foFile = tempFilename + ".fo";


foSettings.setFoDumpFile(new java.io.File(foFile));
}
foSettings.setWmlPackage(wordMLPackage);

// exporter writes to an OutputStream.
try {
String outputFile = tempFilename + ".pdf";
OutputStream os = new java.io.FileOutputStream(outputFile);


// Don't care what type of exporter you use
Docx4J.toFO(foSettings, os, Docx4J.FLAG_NONE);


Thanks

Re: PDF Conversion on Unix server

PostPosted: Tue Jul 01, 2014 10:45 pm
by jason
Do you see log entries similar to:

Code: Select all
ERROR org.docx4j.fonts.fop.util.FopConfigUtil .declareFonts line 92 - Document font courier new is not mapped to a physical font!
ERROR org.docx4j.fonts.fop.util.FopConfigUtil .declareFonts line 92 - Document font times new roman is not mapped to a physical font!
ERROR org.docx4j.fonts.fop.util.FopConfigUtil .declareFonts line 92 - Document font tahoma is not mapped to a physical font!


WARN org.apache.fop.apps.FOUserAgent .processEvent line 94 - Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
WARN org.apache.fop.apps.FOUserAgent .processEvent line 94 - Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".



The fonts which you want to use have to be installed on the server.

If a font is not installed, IdentityPlusMapper allows you to map a required font to some font which is actually present (as in your sample code).

Feel free to send us a simple test case; be sure to identify/highlight the differences you are seeing.