Search in sources :

Example 6 with Docx4JException

use of org.docx4j.openpackaging.exceptions.Docx4JException in project flexmark-java by vsch.

the class DocxConverterCommonMark method main.

public static void main(String[] args) {
    final String markdown = "### header\n" + "1. List item started from 1\n" + "### header \n" + "1. List item started from 1\n" + "1. List item continued 2\n" + "### test\n" + "1. List item started from 1\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-issue-176.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 7 with Docx4JException

use of org.docx4j.openpackaging.exceptions.Docx4JException in project flexmark-java by vsch.

the class ComboDocxConverterIssuesSpecTest method fullTestSpecComplete.

@Override
protected void fullTestSpecComplete() {
    if (!DUMP_ALL_TESTS_FILES || myPackage == null)
        return;
    // write it out to file, hard-coded for now                    IGNORE
    File file = new File(String.format("%s%s.docx", PROJECT_ROOT_DIRECTORY, FILE_ALL_TESTS_DUMP_NAME));
    File file2 = new File(String.format("%s%s.xml", PROJECT_ROOT_DIRECTORY, FILE_ALL_TESTS_DUMP_NAME));
    WordprocessingMLPackage mlPackage = myPackage;
    try {
        mlPackage.save(file, Docx4J.FLAG_SAVE_ZIP_FILE);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        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();
    }
}
Also used : WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException)

Example 8 with Docx4JException

use of org.docx4j.openpackaging.exceptions.Docx4JException in project flexmark-java by vsch.

the class ComboDocxConverterSpecTest method fullTestSpecComplete.

@Override
protected void fullTestSpecComplete() {
    if (!DUMP_ALL_TESTS_FILES || myPackage == null)
        return;
    // write it out to file, hard-coded for now                    IGNORE
    File file = new File(String.format("%s%s.docx", PROJECT_ROOT_DIRECTORY, FILE_ALL_TESTS_DUMP_NAME));
    File file2 = new File(String.format("%s%s.xml", PROJECT_ROOT_DIRECTORY, FILE_ALL_TESTS_DUMP_NAME));
    WordprocessingMLPackage mlPackage = myPackage;
    try {
        mlPackage.save(file, Docx4J.FLAG_SAVE_ZIP_FILE);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        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();
    }
}
Also used : WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException)

Example 9 with Docx4JException

use of org.docx4j.openpackaging.exceptions.Docx4JException in project flexmark-java by vsch.

the class ComboDocxConverterSpecTest 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);
        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)

Example 10 with Docx4JException

use of org.docx4j.openpackaging.exceptions.Docx4JException in project TranskribusCore by Transkribus.

the class TrpTxtBuilder method main.

public static void main(String[] args) {
    // final String path = "/mnt/dea_scratch/TRP/Bentham_box_002_GT";
    final String path = "X:/TRP/Bentham_box_002_GT";
    try {
        TrpDoc doc = LocalDocReader.load(path);
        writeTxtForDoc(doc, true, false, true, new File("TxtExportTest.txt"), null, null, new ExportCache());
    } catch (JAXBException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Docx4JException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ExportCache(eu.transkribus.core.model.builder.ExportCache) TrpDoc(eu.transkribus.core.model.beans.TrpDoc) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) File(java.io.File) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException)

Aggregations

Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)19 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)10 File (java.io.File)7 IOException (java.io.IOException)4 SpecExample (com.vladsch.flexmark.spec.SpecExample)3 FileOutputStream (java.io.FileOutputStream)3 Save (org.docx4j.openpackaging.io3.Save)3 Node (com.vladsch.flexmark.ast.Node)2 DocxRenderer (com.vladsch.flexmark.docx.converter.internal.DocxRenderer)2 Parser (com.vladsch.flexmark.parser.Parser)2 FileNotFoundException (java.io.FileNotFoundException)2 BigInteger (java.math.BigInteger)2 Load3 (org.docx4j.openpackaging.io3.Load3)2 UnzippedPartStore (org.docx4j.openpackaging.io3.stores.UnzippedPartStore)2 ZipPartStore (org.docx4j.openpackaging.io3.stores.ZipPartStore)2 OpcPackage (org.docx4j.openpackaging.packages.OpcPackage)2 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 FootnoteBlock (com.vladsch.flexmark.ext.footnotes.FootnoteBlock)1 TrpDoc (eu.transkribus.core.model.beans.TrpDoc)1 ExportCache (eu.transkribus.core.model.builder.ExportCache)1