/** * Load a Docx Document from a File */ public static WordprocessingMLPackage load(File inFile) throws Docx4JException { return WordprocessingMLPackage.load(inFile); }
/** * Load a Docx Document from an InputStream */ public static WordprocessingMLPackage load(InputStream inStream) throws Docx4JException { return WordprocessingMLPackage.load(inStream); }
public static void main(String[] args) throws Exception { String inputfilepath = System.getProperty("user.dir") + "/sample-docs/Table.docx"; //String inputfilepath = System.getProperty("user.dir") + "/sample-docs/Word2007-fonts.docx"; WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath)); MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart(); org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document)documentPart.getJaxbElement(); Writer out = new OutputStreamWriter(System.out); extractText(wmlDocumentEl, out); //out.flush(); out.close(); }
public static void main(String[] args) throws Exception { String filepath = System.getProperty("user.dir") + "/sample-docs/word/FontEmbedded.docx"; WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(filepath)); wordMLPackage.getMainDocumentPart().getFontTablePart().processEmbeddings(); }
/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/unmarshallFromTemplateExample.docx"; String outputfilepath = System.getProperty("user.dir") + "/OUT_VariableReplace.docx"; WordprocessingMLPackage pkgIn = WordprocessingMLPackage.load(new java.io.File(inputfilepath)); FromVariableReplacement migrator = new FromVariableReplacement(); WordprocessingMLPackage pkgOut = migrator.migrate(pkgIn); SaveToZipFile saver = new SaveToZipFile(pkgOut); saver.save(outputfilepath); }
/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { String inputfilepath = System.getProperty("user.dir") + "/TEST1.docx"; String outputfilepath = System.getProperty("user.dir") + "/OUT_TEST1.docx"; WordprocessingMLPackage pkgIn = WordprocessingMLPackage.load(new java.io.File(inputfilepath)); FromMergeFields migrator = new FromMergeFields(); WordprocessingMLPackage pkgOut = migrator.migrate(pkgIn); SaveToZipFile saver = new SaveToZipFile(pkgOut); saver.save(outputfilepath); }
/** * @param args * @throws Docx4JException */ public static void main(String[] args) throws Docx4JException { WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load( new java.io.File( System.getProperty("user.dir") + "/aq1.docx")); FieldUpdater fu = new FieldUpdater(wordMLPackage); fu.update(true); System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)); }
/** * @param args */ public static void main(String[] args) throws Exception { inputfilepath = System.getProperty("user.dir") // + "/hr.docx"; // + "/sample-docs/word/sample-docx.docx"; // + "/sample-docs/word/2003/word2003-vml.docx"; // + "/table-nested.docx"; + "/hlink.docx"; WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage .load(new java.io.File(inputfilepath)); HtmlExporterNonXSLT withoutXSLT = new HtmlExporterNonXSLT(wordMLPackage, new HTMLConversionImageHandler("c:\\temp", "/bar", true) ); log.info(XmlUtils.w3CDomNodeToString( withoutXSLT.export())); // Wondering where <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> // comes from? See http://stackoverflow.com/questions/1409091/how-do-i-prevent-the-java-xml-transformer-using-html-method-from-adding-meta }
public static void main(String[] args) throws Exception { boolean save=true; String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/unmarshallFromTemplateDirtyExample.docx"; WordprocessingMLPackage wmlPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath)); // Before .. note attributes w:rsidRDefault="00D15781" w:rsidR="00D15781" System.out.println(XmlUtils.marshaltoString(wmlPackage.getMainDocumentPart().getJaxbElement(), true, true)); prepare(wmlPackage); System.out.println(XmlUtils.marshaltoString(wmlPackage.getMainDocumentPart().getJaxbElement(), true, true)); // Save it if (save) { SaveToZipFile saver = new SaveToZipFile(wmlPackage); saver.save(System.getProperty("user.dir") + "/OUT_VariablePrepare.docx"); System.out.println("Saved"); } }
public static void main(String[] args) throws Exception { WordprocessingMLPackage wmlPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
.load(new java.io.File(inputfilepath)); MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
public static void main(String[] args) throws Exception { .load(new java.io.File( System.getProperty("user.dir") + "/SmartArt/OUT-xx.docx"));
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
saver.save(baos); byte[] template = baos.toByteArray(); WordprocessingMLPackage target = WordprocessingMLPackage.load( new ByteArrayInputStream(template));
public static WordprocessingMLPackage getDefaultTemplate(InputStream inputStream) { try { final WordprocessingMLPackage mlPackage = WordprocessingMLPackage.load(inputStream); return mlPackage; } catch (Docx4JException e) { e.printStackTrace(); } return null; }
/** * Load a Docx Document from a File */ public static WordprocessingMLPackage load(File inFile) throws Docx4JException { return WordprocessingMLPackage.load(inFile); }
/** * Load a Docx Document from an InputStream */ public static WordprocessingMLPackage load(InputStream inStream) throws Docx4JException { return WordprocessingMLPackage.load(inStream); }
public static void main(String[] args) throws Exception { String inputfilepath = System.getProperty("user.dir") + "/sample-docs/Table.docx"; //String inputfilepath = System.getProperty("user.dir") + "/sample-docs/Word2007-fonts.docx"; WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath)); MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart(); org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document)documentPart.getJaxbElement(); Writer out = new OutputStreamWriter(System.out); extractText(wmlDocumentEl, out); //out.flush(); out.close(); }
protected void loadDocument() { if (reportTemplate == null) throw new NullPointerException("Template file can't be null."); try { wordprocessingMLPackage = WordprocessingMLPackage.load(reportTemplate.getDocumentContent()); documentWrapper = new DocumentWrapper(new DocxFormatterDelegate(this), wordprocessingMLPackage); } catch (Docx4JException e) { throw wrapWithReportingException(String.format("An error occurred while reading docx template. File name [%s]", reportTemplate.getDocumentName()), e); } }