use of org.docx4j.convert.out.FOSettings in project docx4j-template by vindell.
the class Docx4jUtils method toP.
public static void toP(WordprocessingMLPackage wordMLPackage, String outPath) throws Exception {
OutputStream os = new FileOutputStream(outPath);
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
}
use of org.docx4j.convert.out.FOSettings in project docx4j-template by vindell.
the class WordprocessingMLPackageWriter method writeToPDFWhithFo.
/**
* 将 {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage} 存为 pdf
*/
public void writeToPDFWhithFo(WordprocessingMLPackage wmlPackage, OutputStream output) throws IOException, Docx4JException {
Assert.notNull(wmlPackage, " wmlPackage is not specified!");
Assert.notNull(output, " output is not specified!");
try {
// 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;
// Refresh the values of DOCPROPERTY fields
FieldUpdater updater = new FieldUpdater(wmlPackage);
updater.update(true);
// .. example of mapping font Times New Roman which doesn't have certain Arabic glyphs
// eg Glyph "ي" (0x64a, afii57450) not available in font "TimesNewRomanPS-ItalicMT".
// eg Glyph "ج" (0x62c, afii57420) not available in font "TimesNewRomanPS-ItalicMT".
// to a font which does
PhysicalFonts.get("Arial Unicode MS");
// FO exporter setup (required)
// .. the FOSettings object
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wmlPackage);
foSettings.setApacheFopMime("application/pdf");
// Document format:
// The default implementation of the FORenderer that uses Apache Fop will output
// a PDF document if nothing is passed via
// foSettings.setApacheFopMime(apacheFopMime)
// apacheFopMime can be any of the output formats defined in org.apache.fop.apps.MimeConstants eg org.apache.fop.apps.MimeConstants.MIME_FOP_IF or
// FOSettings.INTERNAL_FO_MIME if you want the fo document as the result.
// foSettings.setApacheFopMime(FOSettings.INTERNAL_FO_MIME);
// Specify whether PDF export uses XSLT or not to create the FO
// (XSLT takes longer, but is more complete).
// Don't care what type of exporter you use
Docx4J.toFO(foSettings, output, Docx4J.FLAG_EXPORT_PREFER_XSL);
// Prefer the exporter, that uses a xsl transformation
// Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
// Prefer the exporter, that doesn't use a xsl transformation (= uses a visitor)
// faster, but not yet at feature parity
// Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_NONXSL);
// Clean up, so any ObfuscatedFontPart temp files can be deleted
// if (wordMLPackage.getMainDocumentPart().getFontTablePart()!=null) {
// wordMLPackage.getMainDocumentPart().getFontTablePart().deleteEmbeddedFontTempFiles();
// }
// This would also do it, via finalize() methods
updater = null;
foSettings = null;
wmlPackage = null;
} finally {
IOUtils.closeQuietly(output);
}
}
Aggregations