本文整理汇总了Java中org.docx4j.Docx4J.toPDF方法的典型用法代码示例。如果您正苦于以下问题:Java Docx4J.toPDF方法的具体用法?Java Docx4J.toPDF怎么用?Java Docx4J.toPDF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.docx4j.Docx4J
的用法示例。
在下文中一共展示了Docx4J.toPDF方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertDocxToPDF
import org.docx4j.Docx4J; //导入方法依赖的package包/类
/**
* docx文档转换为PDF
*
* @param wordMLPackage
* @param pdfPath PDF文档存储路径
* @throws Exception
*/
public static void convertDocxToPDF(WordprocessingMLPackage wordMLPackage,
String pdfPath)
throws Exception {
//HashSet<String> features = new HashSet<>();
//features.add(PP_PDF_APACHEFOP_DISABLE_PAGEBREAK_LIST_ITEM);
//WordprocessingMLPackage process = Preprocess.process(wordMLPackage, features);
FileOutputStream fileOutputStream = new FileOutputStream(pdfPath);
Docx4J.toPDF(wordMLPackage, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
/*FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
Docx4J.toFO(foSettings, fileOutputStream, Docx4J.FLAG_EXPORT_PREFER_XSL);*/
}
示例2: savePdf
import org.docx4j.Docx4J; //导入方法依赖的package包/类
/**
* 将 {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage} 存为 pdf
*
* @param wordMLPackage
* @return
* @throws Exception
*/
public File savePdf(WordprocessingMLPackage wordMLPackage) throws Exception {
File file = new File(genFilePath() + ".pdf");
OutputStream os = new java.io.FileOutputStream(file);
Docx4J.toPDF(wordMLPackage, os);
os.flush();
os.close();
if (logger.isDebugEnabled()) {
logger.debug("Save to [.pdf]: {}", file.getAbsolutePath());
}
return file;
}
示例3: writeToPDF
import org.docx4j.Docx4J; //导入方法依赖的package包/类
/**
* 将 {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage} 存为 pdf
*/
public void writeToPDF(WordprocessingMLPackage wmlPackage,OutputStream output) throws IOException, Docx4JException {
Assert.notNull(wmlPackage, " wmlPackage is not specified!");
Assert.notNull(output, " output is not specified!");
try {
Docx4J.toPDF(wmlPackage, output); //保存到 pdf 文件
output.flush();
} finally{
IOUtils.closeQuietly(output);
}
}
示例4: execute
import org.docx4j.Docx4J; //导入方法依赖的package包/类
private static void execute(WordprocessingMLPackage wordMLPackage) throws Docx4JException, IOException {
// Pretty print the main document part
System.out.println(
XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true) );
// Optionally save it
if (save) {
String filename = System.getProperty("user.dir") + "/OUT_CreateWordprocessingMLDocument.docx";
wordMLPackage.save(new File(filename) );
System.out.println("Saved " + filename);
}
// FO
if (fo) {
OutputStream baos = new ByteArrayOutputStream();
Exporter<FOSettings> exporter = FOExporterVisitor.getInstance();
FOSettings settings = new FOSettings();
settings.setWmlPackage(wordMLPackage);
settings.setApacheFopMime(FOSettings.INTERNAL_FO_MIME);
exporter.export(settings, baos);
System.out.println( ((ByteArrayOutputStream) baos).toString("UTF-8"));
} else {
Docx4J.toPDF(wordMLPackage,
FileUtils.openOutputStream(new File(System.getProperty("user.dir") + "/OUT_textbox.pdf")));
}
}
示例5: convertToDocXThenPdf
import org.docx4j.Docx4J; //导入方法依赖的package包/类
public static void convertToDocXThenPdf(File html, File pdf) throws IOException, Docx4JException, JAXBException {
// Create an empty docx package
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
ndp.unmarshalDefaultNumbering();
XHTMLImporterImpl xHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
xHTMLImporter.setHyperlinkStyle("Hyperlink");
// Convert the XHTML, and add it into the empty docx we made
wordMLPackage.getMainDocumentPart().getContent().addAll(xHTMLImporter.convert(html, null));
//wordMLPackage.save( docx );
String regex = null;
PhysicalFonts.setRegex(regex);
try {
wordMLPackage.setFontMapper(new IdentityPlusMapper());
} catch (Exception e) {
e.printStackTrace();
}
// All methods write to an output stream
OutputStream os = new java.io.FileOutputStream(pdf);
// Refresh the values of DOCPROPERTY fields
FieldUpdater updater = new FieldUpdater(wordMLPackage);
updater.update(true);
Docx4J.toPDF(wordMLPackage, os);
System.out.println("Saved: " + pdf.getAbsolutePath());
// Clean up, so any ObfuscatedFontPart temp files can be deleted
if (wordMLPackage.getMainDocumentPart().getFontTablePart() != null) {
wordMLPackage.getMainDocumentPart().getFontTablePart().deleteEmbeddedFontTempFiles();
}
}
示例6: convert
import org.docx4j.Docx4J; //导入方法依赖的package包/类
@Override
public void convert() throws Exception{
loading();
InputStream iStream = inStream;
WordprocessingMLPackage wordMLPackage = getMLPackage(iStream);
processing();
Docx4J.toPDF(wordMLPackage, outStream);
finished();
}
示例7: output
import org.docx4j.Docx4J; //导入方法依赖的package包/类
/** Create a pdf version of the document, using XSL FO.
*
* @param os
* The OutputStream to write the pdf to
* @param settings
* The configuration for the conversion
*
* */
public void output(OutputStream os, PdfSettings settings) throws Docx4JException {
setupSettings(settings, FOSettings.INTERNAL_FO_MIME);
Docx4J.toPDF(wordMLPackage, os);
}