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();
}
}
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();
}
}
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();
}
}
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();
}
}
}
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();
}
}
Aggregations