/** * Save this pkg to an OutputStream. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE * or Docx4J.FLAG_SAVE_FLAT_XML or one of the Docx4J.FLAG_SAVE_ENCRYPTED_ variants * (recommend FLAG_SAVE_ENCRYPTED_AGILE) * * For the FLAG_SAVE_ENCRYPTED_ variants, you need to provide a password. */ public static void save(WordprocessingMLPackage wmlPackage, OutputStream outStream, int flags, String password) throws Docx4JException { wmlPackage.save(outStream, flags, password); }
/** * Save a Docx Document to a File. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE or Docx4J.FLAG_SAVE_FLAT_XML */ public static void save(WordprocessingMLPackage wmlPackage, File outFile, int flags) throws Docx4JException { wmlPackage.save(outFile, flags); }
/** * Save a Docx Document to an OutputStream using flag Docx4J.FLAG_SAVE_ZIP_FILE * * @since 3.3.0 */ public static void save(WordprocessingMLPackage wmlPackage, OutputStream outStream) throws Docx4JException { wmlPackage.save(outStream, Docx4J.FLAG_SAVE_ZIP_FILE); }
/** * Save a Docx Document to a File. * * @since 3.3.0 */ public static void save(WordprocessingMLPackage wmlPackage, File outFile) throws Docx4JException { wmlPackage.save(outFile, Docx4J.FLAG_SAVE_ZIP_FILE); }
/** * Save a Docx Document to a File. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE * or Docx4J.FLAG_SAVE_FLAT_XML or one of the Docx4J.FLAG_SAVE_ENCRYPTED_ variants * (recommend FLAG_SAVE_ENCRYPTED_AGILE) * * For the FLAG_SAVE_ENCRYPTED_ variants, you need to provide a password. */ public static void save(WordprocessingMLPackage wmlPackage, File outFile, int flags, String password) throws Docx4JException { wmlPackage.save(outFile, flags, password); }
/** * Save a Docx Document to an OutputStream. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE or Docx4J.FLAG_SAVE_FLAT_XML */ public static void save(WordprocessingMLPackage wmlPackage, OutputStream outStream, int flags) throws Docx4JException { wmlPackage.save(outStream, flags); }
public static void main(String[] args) throws Docx4JException { String input_DOCX = System.getProperty("user.dir") + "/Altered2010.docx"; WordprocessingMLPackage wordMLPackage = Docx4J.load(new File(input_DOCX)); UpdateXmlFromDocumentSurface updater = new UpdateXmlFromDocumentSurface(wordMLPackage, false); List<CustomXmlPart> parts = updater.updateCustomXmlParts(); System.out.println( parts.get(0).getXML() ); // or we can save the docx updater.pkg.save(new File(System.getProperty("user.dir") + "/OUT_UpdateXmlFromDocumentSurface.docx")); }
wordMLPackage.save(new java.io.File(filename) ); System.out.println("Saved " + filename);
blockPkg.save(baos, Docx4J.FLAG_SAVE_FLAT_XML);
/** * Render the tree of nodes to DocX. * * @param node the root node * @return the rendered HTML */ public String render(Node node) { WordprocessingMLPackage mlPackage = getDefaultTemplate(); render(node, mlPackage); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { mlPackage.save(outputStream, Docx4J.FLAG_SAVE_FLAT_XML); final String s = options.get(RENDER_BODY_ONLY) ? XmlFormatter.formatDocumentBody(outputStream.toString("UTF-8")) : XmlDocxSorter.sortDocumentParts(outputStream.toString("UTF-8")); return s; } catch (Docx4JException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
/** * Save a Docx Document to a File. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE * or Docx4J.FLAG_SAVE_FLAT_XML or one of the Docx4J.FLAG_SAVE_ENCRYPTED_ variants * (recommend FLAG_SAVE_ENCRYPTED_AGILE) * * For the FLAG_SAVE_ENCRYPTED_ variants, you need to provide a password. */ public static void save(WordprocessingMLPackage wmlPackage, File outFile, int flags, String password) throws Docx4JException { wmlPackage.save(outFile, flags, password); }
/** * Save a Docx Document to an OutputStream using flag Docx4J.FLAG_SAVE_ZIP_FILE * * @since 3.3.0 */ public static void save(WordprocessingMLPackage wmlPackage, OutputStream outStream) throws Docx4JException { wmlPackage.save(outStream, Docx4J.FLAG_SAVE_ZIP_FILE); }
/** * Save a Docx Document to a File. * * @since 3.3.0 */ public static void save(WordprocessingMLPackage wmlPackage, File outFile) throws Docx4JException { wmlPackage.save(outFile, Docx4J.FLAG_SAVE_ZIP_FILE); }
/** * Save this pkg to an OutputStream. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE * or Docx4J.FLAG_SAVE_FLAT_XML or one of the Docx4J.FLAG_SAVE_ENCRYPTED_ variants * (recommend FLAG_SAVE_ENCRYPTED_AGILE) * * For the FLAG_SAVE_ENCRYPTED_ variants, you need to provide a password. */ public static void save(WordprocessingMLPackage wmlPackage, OutputStream outStream, int flags, String password) throws Docx4JException { wmlPackage.save(outStream, flags, password); }
/** * Save a Docx Document to a File. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE or Docx4J.FLAG_SAVE_FLAT_XML */ public static void save(WordprocessingMLPackage wmlPackage, File outFile, int flags) throws Docx4JException { wmlPackage.save(outFile, flags); }
/** * Save a Docx Document to an OutputStream. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE or Docx4J.FLAG_SAVE_FLAT_XML */ public static void save(WordprocessingMLPackage wmlPackage, OutputStream outStream, int flags) throws Docx4JException { wmlPackage.save(outStream, flags); }
public static void main(String[] args) throws Exception { String xhtml= "<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:100%;\"><tbody><tr><td>test</td><td>test</td></tr><tr><td>test</td><td>test</td></tr><tr><td>test</td><td>test</td></tr></tbody></table>"; // To docx, with content controls WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage); wordMLPackage.getMainDocumentPart().getContent().addAll( XHTMLImporter.convert( xhtml, null) ); wordMLPackage.save(new java.io.File("D://sample.docx")); }
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); // //Do something with wordMLPackage // ByteArrayOutputStream baos = new ByteArrayOutputStream(); wordMLPackage.save(baos); //You have your byte array //Optionally, you can also get byte array data souce from baos assuming it's .docx file ByteArrayDataSource bads = new ByteArrayDataSource(baos.toByteArray(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
public static void main(String[] args) throws Exception { String xhtml= "<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:100%;\"><tbody><tr><td>test</td><td>test</td></tr><tr><td>test</td><td>test</td></tr><tr><td>test</td><td>test</td></tr></tbody></table>"; // To docx, with content controls WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackage); wordMLPackage.getMainDocumentPart().getContent().addAll( XHTMLImporter.convert( xhtml, null) ); wordMLPackage.save(new java.io.File("D://sample.docx")); }
public static void main(String[] args) throws Docx4JException { String input_DOCX = System.getProperty("user.dir") + "/Altered2010.docx"; WordprocessingMLPackage wordMLPackage = Docx4J.load(new File(input_DOCX)); UpdateXmlFromDocumentSurface updater = new UpdateXmlFromDocumentSurface(wordMLPackage, false); List<CustomXmlPart> parts = updater.updateCustomXmlParts(); System.out.println( parts.get(0).getXML() ); // or we can save the docx updater.pkg.save(new File(System.getProperty("user.dir") + "/OUT_UpdateXmlFromDocumentSurface.docx")); }