Search in sources :

Example 26 with WordprocessingMLPackage

use of org.docx4j.openpackaging.packages.WordprocessingMLPackage in project docx4j-template by vindell.

the class Docx4jUtils method docxToPdf.

/**
 * docx文档转换为PDF
 *
 * @param docx
 *            docx文档
 * @param pdfPath
 *            PDF文档存储路径
 * @throws Exception
 *             可能为Docx4JException, FileNotFoundException, IOException等
 */
public static void docxToPdf(String docxPath, String pdfPath) throws Exception {
    OutputStream output = null;
    try {
        output = new FileOutputStream(pdfPath);
        WordprocessingMLPackage wmlPackage = WordprocessingMLPackage.load(new File(docxPath));
        WMLPACKAGE_BUILDER.configChineseFonts(wmlPackage).configSimSunFont(wmlPackage);
        WMLPACKAGE_WRITER.writeToPDF(wmlPackage, output);
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        IOUtils.closeQuietly(output);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) IOException(java.io.IOException) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException)

Example 27 with WordprocessingMLPackage

use of org.docx4j.openpackaging.packages.WordprocessingMLPackage in project docx4j-template by vindell.

the class WordprocessingMLBeetlTemplate_Test method test.

@Test
public void test() throws Exception {
    variables.put("title", "变量替换测试");
    variables.put("content", "测试效果不错");
    WordprocessingMLPackage wordMLPackage = beetlTemplate.process("/tpl/beetl.tpl", variables);
    File outputDocx = new java.io.File("src/test/resources/output/beetlTemplate_output.docx");
    wordMLPackage.save(outputDocx);
}
Also used : WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) Test(org.junit.Test)

Example 28 with WordprocessingMLPackage

use of org.docx4j.openpackaging.packages.WordprocessingMLPackage in project docx4j-template by vindell.

the class WordprocessingMLRythmTemplate_Test method test.

@Test
public void test() throws Exception {
    variables.put("title", "变量替换测试");
    variables.put("content", "测试效果不错");
    WordprocessingMLPackage wordMLPackage = rythmTemplate.process("/tpl/rythm.tpl", variables);
    File outputDocx = new java.io.File("src/test/resources/output/rythmTemplate_output.docx");
    wordMLPackage.save(outputDocx);
}
Also used : WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) Test(org.junit.Test)

Example 29 with WordprocessingMLPackage

use of org.docx4j.openpackaging.packages.WordprocessingMLPackage in project docx4j-template by vindell.

the class WordprocessingMLThymeleafTemplate_Test method test.

@Test
public void test() throws Exception {
    variables.put("title", "变量替换测试");
    variables.put("content", "测试效果不错");
    WordprocessingMLPackage wordMLPackage = thymeleafTemplate.process("/tpl/thymeleaf.tpl", variables);
    File outputDocx = new java.io.File("src/test/resources/output/thymeleafTemplate_output.docx");
    wordMLPackage.save(outputDocx);
}
Also used : WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) Test(org.junit.Test)

Example 30 with WordprocessingMLPackage

use of org.docx4j.openpackaging.packages.WordprocessingMLPackage in project docx4j-template by vindell.

the class WordprocessingMLJetbrickTemplate_Test method test.

@Test
public void test() throws Exception {
    variables.put("title", "变量替换测试");
    variables.put("content", "测试效果不错");
    WordprocessingMLPackage wordMLPackage = jetbrickTemplate.process("/tpl/jetbrick.jetx", variables);
    File outputDocx = new java.io.File("src/test/resources/output/jetbrickTemplate_output.docx");
    wordMLPackage.save(outputDocx);
}
Also used : WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) Test(org.junit.Test)

Aggregations

WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)67 File (java.io.File)50 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)22 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)11 XHTMLImporterImpl (org.docx4j.convert.in.xhtml.XHTMLImporterImpl)9 OutputStream (java.io.OutputStream)8 ObjectFactory (org.docx4j.wml.ObjectFactory)8 Test (org.junit.Test)8 P (org.docx4j.wml.P)7 Text (org.docx4j.wml.Text)7 FileOutputStream (java.io.FileOutputStream)6 FileInputStream (java.io.FileInputStream)5 Body (org.docx4j.wml.Body)5 Tbl (org.docx4j.wml.Tbl)5 TraversalUtil (org.docx4j.TraversalUtil)4 NumberingDefinitionsPart (org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart)4 R (org.docx4j.wml.R)4 RPr (org.docx4j.wml.RPr)4 SpecExample (com.vladsch.flexmark.spec.SpecExample)3 IOException (java.io.IOException)3