Package org.docx4j
Class Docx4J
java.lang.Object
org.docx4j.Docx4J
This is a facade for some typical uses of Docx4J:
- Loading a document
- Saving a document
- Binding xml to content controls in a document
- Exporting the document (to HTML, or PDF and other formats supported by the FO renderer)
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic Booleanstatic Booleanstatic Booleanstatic Booleanstatic Booleanstatic final intInsert the data of the xml in the content controls Not needed, if the document will only be opened in Word and not converted to other formats.static final intinject the passed xml into the document if you don't do this step, then the xml in the document will be used.static final intRemove the content controls of the documentstatic final intRemove any xml parts from the document that are used with the content controls.static final intIf available export the document using a visitorstatic final intIf available export the document using a xsl transformationstatic final intNo flags passed, do the defaultstatic final intAgile encryption: This is used by Word 2010, it uses an XML EncryptionInfo structure.static final intRC4 is weak, so don't use it unless you have to for backwards compatibility purposes (ie the applications to be used for reading your docx don't support anything better).static final intStandard encryption: This approach uses a binary EncryptionInfo structure.static final intSave the document as a flat xml documentstatic final intSave the document in a zip container (default docx)static final Stringstatic final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidbind(WordprocessingMLPackage wmlPackage, InputStream xmlDocument, int flags) Bind the content controls of the passed document to the xml.static voidbind(WordprocessingMLPackage wmlPackage, String xmlDocument, int flags) Bind the content controls of the passed document to the xml.static voidbind(WordprocessingMLPackage wmlPackage, Answers answers, int flags) Bind the content controls of the passed document to the xml (here using optional standardised Answers format).static voidbind(WordprocessingMLPackage wmlPackage, Document xmlDocument, int flags) Bind the content controls of the passed document to the xml.static voidbind(WordprocessingMLPackage wmlPackage, Document xmlDocument, int flags, DocxFetcher docxFetcher) Bind the content controls of the passed document to the xml.static voidbind(WordprocessingMLPackage wmlPackage, Document xmlDocument, int flags, DocxFetcher docxFetcher, XsltProvider xsltProvider, String xsltFinisherfilename, Map<String, Map<String, Object>> finisherParams) Bind the content controls of the passed document to the xml, applying some formatting finishing touches to the final docx.static WordprocessingMLPackageclone(WordprocessingMLPackage wmlPackage) Duplicate the documentstatic FOSettingsCreate the configuration object for conversions that are done via xsl-fostatic HTMLSettingsCreate the configuration object for conversions to htmlprotected static Stringprotected static Exporter<FOSettings>getFOExporter(int flags) protected static Exporter<HTMLSettings>getHTMLExporter(int flags) protected static voidinsertXMLData(CustomXmlPart customXmlDataStoragePart, Document xmlDocument) static WordprocessingMLPackageLoad a Docx Document from a Filestatic OpcPackageLoad a docx/pptx/xlsx from a File, where you know in advance what type (zip, compound, flat opc) it is.static WordprocessingMLPackageload(InputStream inStream) Load a Docx Document from an InputStreamstatic WordprocessingMLPackageload(PackageIdentifier pkgIdentifier, File inFile) Load a Docx Document from a File, assigning it an identifier for eventingstatic WordprocessingMLPackageload(PackageIdentifier pkgIdentifier, InputStream inStream) Load a Docx Document from an InputStream, assigning it an identifier for eventingstatic booleanstatic booleanstatic booleanpdfViaFO()If the docx4j-export-fo project is present, we'll use FO for PDF export.static booleanIf the docx4j-legacy-converter project is present, we'll use it for PDF export.static booleanprotected static voidremoveDefinedCustomXmlParts(WordprocessingMLPackage wmlPackage, String itemId) protected static voidremoveSDTs(WordprocessingMLPackage wmlPackage) static voidsave(OpcPackage pkg, File outFile) Save a Ddocx/pptx/xlsx to a File.static voidsave(OpcPackage pkg, File outFile, int flags) Save a docx/pptx/xlsx to a File.static voidsave(OpcPackage pkg, File outFile, int flags, String password) Save a docx/pptx/xlsx to a File.static voidsave(OpcPackage pkg, OutputStream outStream) Save a docx/pptx/xlsx to an OutputStream using flag Docx4J.FLAG_SAVE_ZIP_FILEstatic voidsave(OpcPackage pkg, OutputStream outStream, int flags) Save a docx/pptx/xlsx to an OutputStream.static voidsave(OpcPackage pkg, OutputStream outStream, int flags, String password) Save this pkg to an OutputStream.static voidsetEventNotifier(net.engio.mbassy.bus.MBassador<Docx4jEvent> eventbus) static voidtoFO(FOSettings settings, OutputStream outputStream, int flags) Convert the document via xsl-fostatic voidtoHTML(HTMLSettings settings, OutputStream outputStream, int flags) Convert the document to HTMLstatic voidtoHTML(WordprocessingMLPackage wmlPackage, String imageDirPath, String imageTargetUri, OutputStream outputStream) Convert the document to HTMLstatic voidtoPDF(WordprocessingMLPackage wmlPackage, OutputStream outputStream) Convenience method to convert the document to PDF
-
Field Details
-
MIME_PDF
- See Also:
-
MIME_FO
- See Also:
-
FLAG_NONE
public static final int FLAG_NONENo flags passed, do the default- See Also:
-
FLAG_EXPORT_PREFER_XSL
public static final int FLAG_EXPORT_PREFER_XSLIf available export the document using a xsl transformation- See Also:
-
FLAG_EXPORT_PREFER_NONXSL
public static final int FLAG_EXPORT_PREFER_NONXSLIf available export the document using a visitor- See Also:
-
FLAG_SAVE_ZIP_FILE
public static final int FLAG_SAVE_ZIP_FILESave the document in a zip container (default docx)- See Also:
-
FLAG_SAVE_FLAT_XML
public static final int FLAG_SAVE_FLAT_XMLSave the document as a flat xml document- See Also:
-
FLAG_SAVE_ENCRYPTED_BINARYRC4
public static final int FLAG_SAVE_ENCRYPTED_BINARYRC4RC4 is weak, so don't use it unless you have to for backwards compatibility purposes (ie the applications to be used for reading your docx don't support anything better). See further http://blogs.msdn.com/b/david_leblanc/archive/2010/04/16/don-t-use-office-rc4-encryption-really-just-don-t-do-it.aspx- See Also:
-
FLAG_SAVE_ENCRYPTED_STANDARD
public static final int FLAG_SAVE_ENCRYPTED_STANDARDStandard encryption: This approach uses a binary EncryptionInfo structure. It uses Advanced Encryption Standard (AES) as an encryption algorithm and SHA-1 as a hashing algorithm.- See Also:
-
FLAG_SAVE_ENCRYPTED_AGILE
public static final int FLAG_SAVE_ENCRYPTED_AGILEAgile encryption: This is used by Word 2010, it uses an XML EncryptionInfo structure. The encryption and hashing algorithms are specified in the structure and can be for any encryption supported on the host computer.- See Also:
-
FLAG_BIND_INSERT_XML
public static final int FLAG_BIND_INSERT_XMLinject the passed xml into the document if you don't do this step, then the xml in the document will be used.- See Also:
-
FLAG_BIND_BIND_XML
public static final int FLAG_BIND_BIND_XMLInsert the data of the xml in the content controls Not needed, if the document will only be opened in Word and not converted to other formats.- See Also:
-
FLAG_BIND_REMOVE_SDT
public static final int FLAG_BIND_REMOVE_SDTRemove the content controls of the document- See Also:
-
FLAG_BIND_REMOVE_XML
public static final int FLAG_BIND_REMOVE_XMLRemove any xml parts from the document that are used with the content controls.- See Also:
-
NS_CONDITIONS
- See Also:
-
NS_XPATHS
- See Also:
-
NS_QUESTIONS
- See Also:
-
NS_COMPONENTS
- See Also:
-
PART_TO_REMOVE_SCHEMA_TYPES
-
EXPORT_FO_DETECTED
-
EXPORT_DOCUMENTS4J_REMOTE_DETECTED
-
EXPORT_DOCUMENTS4J_LOCAL_DETECTED
-
EXPORT_MICROSOFT_GRAPH_DETECTED
-
EXPORT_LEGACY_CONVERTER_DETECTED
-
-
Constructor Details
-
Docx4J
public Docx4J()
-
-
Method Details
-
setEventNotifier
-
load
Load a docx/pptx/xlsx from a File, where you know in advance what type (zip, compound, flat opc) it is. Typically you'll cast the result to WordprocessingMLPackage or pptx/xlsx equivalent.- Throws:
Docx4JException- Since:
- 6.0.0
-
load
Load a Docx Document from a File- Throws:
Docx4JException
-
load
public static WordprocessingMLPackage load(PackageIdentifier pkgIdentifier, File inFile) throws Docx4JException Load a Docx Document from a File, assigning it an identifier for eventing- Throws:
Docx4JException- Since:
- 3.1.0
-
load
Load a Docx Document from an InputStream- Throws:
Docx4JException
-
load
public static WordprocessingMLPackage load(PackageIdentifier pkgIdentifier, InputStream inStream) throws Docx4JException Load a Docx Document from an InputStream, assigning it an identifier for eventing- Throws:
Docx4JException- Since:
- 3.1.0
-
save
Save a Ddocx/pptx/xlsx to a File.- Throws:
Docx4JException- Since:
- 3.3.0
-
save
Save a docx/pptx/xlsx to a File. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE or Docx4J.FLAG_SAVE_FLAT_XML- Throws:
Docx4JException
-
save
Save a docx/pptx/xlsx to an OutputStream using flag Docx4J.FLAG_SAVE_ZIP_FILE- Throws:
Docx4JException- Since:
- 3.3.0
-
save
Save a docx/pptx/xlsx to an OutputStream. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE or Docx4J.FLAG_SAVE_FLAT_XML- Throws:
Docx4JException
-
save
public static void save(OpcPackage pkg, File outFile, int flags, String password) throws Docx4JException Save a docx/pptx/xlsx 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.- Throws:
Docx4JException
-
save
public static void save(OpcPackage pkg, OutputStream outStream, int flags, String password) throws Docx4JException 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.- Throws:
Docx4JException
-
bind
public static void bind(WordprocessingMLPackage wmlPackage, String xmlDocument, int flags) throws Docx4JException Bind the content controls of the passed document to the xml.- Throws:
Docx4JException
-
bind
public static void bind(WordprocessingMLPackage wmlPackage, InputStream xmlDocument, int flags) throws Docx4JException Bind the content controls of the passed document to the xml.- Throws:
Docx4JException
-
bind
public static void bind(WordprocessingMLPackage wmlPackage, Answers answers, int flags) throws Docx4JException Bind the content controls of the passed document to the xml (here using optional standardised Answers format).- Throws:
Docx4JException
-
bind
public static void bind(WordprocessingMLPackage wmlPackage, Document xmlDocument, int flags) throws Docx4JException Bind the content controls of the passed document to the xml.- Throws:
Docx4JException
-
bind
public static void bind(WordprocessingMLPackage wmlPackage, Document xmlDocument, int flags, DocxFetcher docxFetcher) throws Docx4JException Bind the content controls of the passed document to the xml.- Throws:
Docx4JException
-
bind
public static void bind(WordprocessingMLPackage wmlPackage, Document xmlDocument, int flags, DocxFetcher docxFetcher, XsltProvider xsltProvider, String xsltFinisherfilename, Map<String, Map<String, throws Docx4JExceptionObject>> finisherParams) Bind the content controls of the passed document to the xml, applying some formatting finishing touches to the final docx.- Throws:
Docx4JException- Since:
- 6.1.0
-
insertXMLData
protected static void insertXMLData(CustomXmlPart customXmlDataStoragePart, Document xmlDocument) throws Docx4JException - Throws:
Docx4JException
-
findXPathStorageItemIdInContentControls
-
removeSDTs
- Throws:
Docx4JException
-
removeDefinedCustomXmlParts
protected static void removeDefinedCustomXmlParts(WordprocessingMLPackage wmlPackage, String itemId) -
clone
public static WordprocessingMLPackage clone(WordprocessingMLPackage wmlPackage) throws Docx4JException Duplicate the document- Throws:
Docx4JException
-
createFOSettings
Create the configuration object for conversions that are done via xsl-fo -
toFO
public static void toFO(FOSettings settings, OutputStream outputStream, int flags) throws Docx4JException Convert the document via xsl-fo- Throws:
Docx4JException
-
toPDF
public static void toPDF(WordprocessingMLPackage wmlPackage, OutputStream outputStream) throws Docx4JException Convenience method to convert the document to PDF- Throws:
Docx4JException
-
pdfViaLegacyConverter
public static boolean pdfViaLegacyConverter()If the docx4j-legacy-converter project is present, we'll use it for PDF export.- Returns:
- Since:
- 8.3.1
-
pdfViaFO
public static boolean pdfViaFO()If the docx4j-export-fo project is present, we'll use FO for PDF export.- Returns:
- Since:
- 3.3.0
-
pdfViaDocuments4jRemote
public static boolean pdfViaDocuments4jRemote()- Since:
- 8.2.0
-
pdfViaDocuments4jLocal
public static boolean pdfViaDocuments4jLocal()- Since:
- 8.2.0
-
pdfViaMicrosoftGraph
public static boolean pdfViaMicrosoftGraph()- Since:
- 8.2.7
-
getFOExporter
- Throws:
Docx4JException
-
createHTMLSettings
Create the configuration object for conversions to html -
toHTML
public static void toHTML(HTMLSettings settings, OutputStream outputStream, int flags) throws Docx4JException Convert the document to HTML- Throws:
Docx4JException
-
toHTML
public static void toHTML(WordprocessingMLPackage wmlPackage, String imageDirPath, String imageTargetUri, OutputStream outputStream) throws Docx4JException Convert the document to HTML- Throws:
Docx4JException
-
getHTMLExporter
-