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