by qingliang » Fri Apr 18, 2014 11:51 pm
my code :
--------------------------------------------------
Date startTime = new Date();
String inputfilepath = "e:/123news.docx";
String outputfilepath = "e:/PDF_" + new Date().getTime() + ".pdf";
String regex = null;
WordprocessingMLPackage wordMLPackage;
// Load .docx or Flat OPC .xml
System.out.println("Loading file from " + inputfilepath);
try {
wordMLPackage = WordprocessingMLPackage.load(new java.io.File(
inputfilepath));
FOSettings foSettings = Docx4J.createFOSettings();
Mapper fontMapper = new IdentityPlusMapper();
// URL ttcUrl = new URL("http://localhost/conf/fonts/SimSun.ttc");
// PhysicalFonts.addPhysicalFont("宋体", ttcUrl);
// PhysicalFont font
// = PhysicalFonts.getPhysicalFonts().get("宋体");
//
// fontMapper.getFontMappings().put("宋体", font);
wordMLPackage.setFontMapper(fontMapper);
if (saveFO) {
foSettings
.setFoDumpFile(new java.io.File(inputfilepath + ".fo"));
}
foSettings.setWmlPackage(wordMLPackage);
OutputStream os = new java.io.FileOutputStream(outputfilepath);
// Don't care what type of exporter you use
// foSettings.setApacheFopConfiguration(apacheFopConfiguration)
Docx4J.toFO(foSettings, os, Docx4J.FLAG_NONE);
} catch (Docx4JException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}