Package org.docx4j.documents4j.remote
Class Documents4jRemoteServices
java.lang.Object
org.docx4j.documents4j.remote.Documents4jRemoteServices
- All Implemented Interfaces:
Exporter<Documents4jConversionSettings>
public class Documents4jRemoteServices extends java.lang.Object implements Exporter<Documents4jConversionSettings>
Import/update/export docx/xlsx using Documents4j, with Microsoft Word running
on a remote server.
You can use this to export to PDF, or to update your ToC. It can also import binary
.doc or RTF.
The easiest way to set up documents4j on a remote server is to build it
from https://github.com/documents4j/documents4j using maven, then in
documents4j-server-standalone, create a shaded jar using profile shaded-jar.
Note: to update ToC, you'll need a custom script in documents4j on your remote
server. You can update the script documents4j provides, or you can create
a new one, and in the server code, point to it using System.setProperty
com.documents4j.conversion.msoffice.word_convert.vbs
- Since:
- 8.2.0
- Author:
- jharrop
-
Field Summary
Fields Modifier and Type Field Description protected static Documents4jRemoteServicesinstance -
Constructor Summary
Constructors Constructor Description Documents4jRemoteServices()Configure the converter with default settings.Documents4jRemoteServices(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, long timeout)Configures a worker pool for the converter. -
Method Summary
Modifier and Type Method Description voidexport(java.io.File officeFile, java.io.OutputStream target, com.documents4j.api.DocumentType documentType)Export docx or xlsx file as PDFvoidexport(java.io.File officeFile, java.io.OutputStream target, com.documents4j.api.DocumentType documentType, com.documents4j.api.DocumentType asDocumentType)Export docx or xlsx file as specified com.documents4j.api.DocumentTypevoidexport(Documents4jConversionSettings conversionSettings, java.io.OutputStream outputStream)Export to outputStream as PDF.voidexport(OpcPackage pkg, java.io.OutputStream outputStream)Export WordprocessingMLPackage or SpreadsheetMLPackage as PDFvoidexport(OpcPackage pkg, java.io.OutputStream outputStream, com.documents4j.api.DocumentType asDocumentType)Export WordprocessingMLPackage or SpreadsheetMLPackage as specified com.documents4j.api.DocumentTypestatic Exporter<Documents4jConversionSettings>getInstance()WordprocessingMLPackageimportAsDocx(java.io.File officeFile)Import as a docx from one of the other file types supported by Word.voidimportAsDocx(java.io.File officeFile, java.io.OutputStream target)Import as a docx from one of the other file types supported by Word.voidupdateDocx(java.io.File officeFile, java.io.OutputStream target)Run the script to update the docx (eg ToC).WordprocessingMLPackageupdateDocx(WordprocessingMLPackage pkg)Run the script to update the docx (eg ToC).voidupdateDocx(WordprocessingMLPackage pkg, java.io.OutputStream outputStream)Run the script to update the docx (eg ToC).
-
Field Details
-
Constructor Details
-
Documents4jRemoteServices
public Documents4jRemoteServices()Configure the converter with default settings. -
Documents4jRemoteServices
public Documents4jRemoteServices(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, long timeout)Configures a worker pool for the converter. This worker pool implicitly sets a maximum number of conversions that are concurrently undertaken by the resulting converter. When a converter is requested to concurrently execute more conversions thanmaximumPoolSize, it will queue excess conversions until capacities are available again.
If this number is set too low, the concurrent performance of the resulting converter will be weak compared to a higher number. If this number is set too high, the converter might overheat when accessing the underlying external resource (such as for example an external process or a HTTP connection). A remote converter that shares a conversion server with another converter might also starve these other remote converters.- Parameters:
corePoolSize- The core pool size of the worker pool.maximumPoolSize- The maximum pool size of the worker pool.keepAliveTime- The keep alive time of the worker pool.unit- The time unit of the specified keep alive time.timeout- The timeout for a network request (in ms).
-
-
Method Details
-
getInstance
-
export
public void export(Documents4jConversionSettings conversionSettings, java.io.OutputStream outputStream) throws Docx4JExceptionExport to outputStream as PDF. Make sure you have setOpcPackage in conversionSettings. That's the only value which matters to documents4j.- Specified by:
exportin interfaceExporter<Documents4jConversionSettings>- Throws:
Docx4JException
-
export
Export WordprocessingMLPackage or SpreadsheetMLPackage as PDF- Parameters:
pkg-outputStream-- Throws:
Docx4JException
-
export
public void export(OpcPackage pkg, java.io.OutputStream outputStream, com.documents4j.api.DocumentType asDocumentType) throws Docx4JExceptionExport WordprocessingMLPackage or SpreadsheetMLPackage as specified com.documents4j.api.DocumentType- Parameters:
pkg-outputStream-- Throws:
Docx4JException
-
export
public void export(java.io.File officeFile, java.io.OutputStream target, com.documents4j.api.DocumentType documentType) throws Docx4JExceptionExport docx or xlsx file as PDF- Parameters:
officeFile-target-documentType-- Throws:
Docx4JException
-
export
public void export(java.io.File officeFile, java.io.OutputStream target, com.documents4j.api.DocumentType documentType, com.documents4j.api.DocumentType asDocumentType) throws Docx4JExceptionExport docx or xlsx file as specified com.documents4j.api.DocumentType- Parameters:
officeFile-target-documentType-asDocumentType-- Throws:
Docx4JException
-
updateDocx
public void updateDocx(WordprocessingMLPackage pkg, java.io.OutputStream outputStream) throws Docx4JExceptionRun the script to update the docx (eg ToC). Requires a custom script on the server. Documents4j writes a new docx file to outputStream.- Parameters:
pkg-outputStream-- Throws:
Docx4JException
-
updateDocx
Run the script to update the docx (eg ToC). Requires a custom script on the server. Returns a new WordprocessingMLPackage.- Parameters:
pkg-- Returns:
- Throws:
Docx4JException
-
updateDocx
public void updateDocx(java.io.File officeFile, java.io.OutputStream target) throws Docx4JExceptionRun the script to update the docx (eg ToC). Requires a custom script on the server.- Parameters:
officeFile-target-documentType-- Throws:
Docx4JException
-
importAsDocx
public void importAsDocx(java.io.File officeFile, java.io.OutputStream target) throws Docx4JExceptionImport as a docx from one of the other file types supported by Word.- Parameters:
officeFile-target-documentType-- Throws:
Docx4JException
-
importAsDocx
Import as a docx from one of the other file types supported by Word.- Parameters:
officeFile-- Throws:
Docx4JException
-