Search in sources :

Example 61 with WordprocessingMLPackage

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

the class Word_解压_Unzip_S3_Test method unzipWord.

public void unzipWord(String fileName, String outFilePath) throws Exception {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(fileName));
    File baseDir = new File(outFilePath);
    baseDir.mkdir();
    UnzippedPartStore ups = new UnzippedPartStore(baseDir);
    ups.setSourcePartStore(wordMLPackage.getSourcePartStore());
    Save saver = new Save(wordMLPackage, ups);
    saver.save(null);
}
Also used : UnzippedPartStore(org.docx4j.openpackaging.io3.stores.UnzippedPartStore) Save(org.docx4j.openpackaging.io3.Save) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) File(java.io.File)

Example 62 with WordprocessingMLPackage

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

the class WordprocessingMLFreemarkerTemplate_Test method test.

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

Example 63 with WordprocessingMLPackage

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

the class WordprocessingMLHttlTemplate_Test method test.

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

Example 64 with WordprocessingMLPackage

use of org.docx4j.openpackaging.packages.WordprocessingMLPackage in project flexmark-java by vsch.

the class DocxConverterPegdown method main.

public static void main(String[] args) {
    final String markdown = "#Heading\n" + "-----\n" + "paragraph text \n" + "lazy continuation\n" + "\n" + "* list item\n" + "    > block quote\n" + "    lazy continuation\n" + "\n" + "~~~info\n" + "   with uneven indent\n" + "      with uneven indent\n" + "indented code\n" + "~~~ \n" + "\n" + "       with uneven indent\n" + "          with uneven indent\n" + "    indented code\n" + "1. numbered item 1   \n" + "1. numbered item 2   \n" + "1. numbered item 3   \n" + "    - bullet item 1   \n" + "    - bullet item 2   \n" + "    - bullet item 3   \n" + "        1. numbered sub-item 1   \n" + "        1. numbered sub-item 2   \n" + "        1. numbered sub-item 3   \n" + "    \n" + "    ~~~info\n" + "       with uneven indent\n" + "          with uneven indent\n" + "    indented code\n" + "    ~~~ \n" + "    \n" + "           with uneven indent\n" + "              with uneven indent\n" + "        indented code\n" + "";
    System.out.println("markdown\n");
    System.out.println(markdown);
    final Parser PARSER = Parser.builder(OPTIONS).build();
    final DocxRenderer RENDERER = DocxRenderer.builder(OPTIONS).build();
    Node document = PARSER.parse(markdown);
    // to get XML
    String xml = RENDERER.render(document);
    // or to control the package
    final WordprocessingMLPackage template = DocxRenderer.getDefaultTemplate();
    RENDERER.render(document, template);
    File file = new File("/Users/vlad/src/pdf/flexmark-java.docx");
    try {
        template.save(file, Docx4J.FLAG_SAVE_ZIP_FILE);
    } catch (Docx4JException e) {
        e.printStackTrace();
    }
}
Also used : Node(com.vladsch.flexmark.ast.Node) DocxRenderer(com.vladsch.flexmark.docx.converter.internal.DocxRenderer) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException) Parser(com.vladsch.flexmark.parser.Parser)

Example 65 with WordprocessingMLPackage

use of org.docx4j.openpackaging.packages.WordprocessingMLPackage in project flexmark-java by vsch.

the class ComboDocxConverterIssuesSpecTest method testCase.

@Override
protected void testCase(final Node node, final DataHolder options) {
    if (!DUMP_TEST_CASE_FILES)
        return;
    final SpecExample specExample = example();
    if (!specExample.isFullSpecExample() && !specExample.getSection().isEmpty()) {
        // write it out to file, hard-coded for now                    IGNORE
        File file = new File(String.format("%s%s%s_%d.docx", PROJECT_ROOT_DIRECTORY, FILE_TEST_CASE_DUMP_LOCATION, specExample.getSection(), specExample.getExampleNumber()));
        File file2 = new File(String.format("%s%s%s_%d.xml", PROJECT_ROOT_DIRECTORY, FILE_TEST_CASE_DUMP_LOCATION, specExample.getSection(), specExample.getExampleNumber()));
        WordprocessingMLPackage mlPackage = DocxRenderer.getDefaultTemplate();
        RENDERER.withOptions(options).render(node, mlPackage);
        File parentDir = file.getParentFile();
        if (!parentDir.exists()) {
            parentDir.mkdirs();
        }
        try {
            mlPackage.save(file, Docx4J.FLAG_SAVE_ZIP_FILE);
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            try {
                mlPackage.save(outputStream, Docx4J.FLAG_SAVE_FLAT_XML);
                final String xml = outputStream.toString("UTF-8");
                final String s = XmlDocxSorter.sortDocumentParts(xml);
                FileWriter fileWriter = new FileWriter(file2);
                fileWriter.append(s);
                fileWriter.append('\n');
                fileWriter.close();
            } catch (Docx4JException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (Docx4JException e) {
            e.printStackTrace();
        }
    }
}
Also used : SpecExample(com.vladsch.flexmark.spec.SpecExample) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException)

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