Class Documents4jLocalServices

java.lang.Object
org.docx4j.documents4j.local.Documents4jLocalServices
All Implemented Interfaces:
Exporter<Documents4jConversionSettings>

public class Documents4jLocalServices
extends java.lang.Object
implements Exporter<Documents4jConversionSettings>
Import/update/export docx/xlsx using Documents4j, with Microsoft Word running locally. You can use this to export to PDF, or to update your ToC. It can also import binary .doc or RTF. You can customise your conversion script by specifying one in docx4j.properties, under key: com.documents4j.conversion.msoffice.word_convert.vbs If you do not do that, the document4j's default script will be used (which doesn't update ToC). A sample override script (which updates ToC) is in docx4j-samples-resources. You'll need that script (or one like it) to update ToC.
Since:
8.2.0
Author:
jharrop
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected static Documents4jLocalServices instance  
  • Constructor Summary

    Constructors
    Constructor Description
    Documents4jLocalServices()
    Configure the converter with default settings.
    Documents4jLocalServices​(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
    void export​(java.io.File officeFile, java.io.OutputStream target, com.documents4j.api.DocumentType documentType)
    Export docx or xlsx file as PDF
    void export​(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.DocumentType
    void export​(Documents4jConversionSettings conversionSettings, java.io.OutputStream outputStream)
    Export to outputStream as PDF.
    void export​(OpcPackage pkg, java.io.OutputStream outputStream)
    Export WordprocessingMLPackage or SpreadsheetMLPackage as PDF
    void export​(OpcPackage pkg, java.io.OutputStream outputStream, com.documents4j.api.DocumentType asDocumentType)
    Export WordprocessingMLPackage or SpreadsheetMLPackage as specified com.documents4j.api.DocumentType
    static Exporter<Documents4jConversionSettings> getInstance()  
    WordprocessingMLPackage importAsDocx​(java.io.File officeFile)
    Import as a docx from one of the other file types supported by Word.
    void importAsDocx​(java.io.File officeFile, java.io.OutputStream target)
    Import as a docx from one of the other file types supported by Word.
    void updateDocx​(java.io.File officeFile, java.io.OutputStream target)
    Run the script to update the docx (eg ToC).
    WordprocessingMLPackage updateDocx​(WordprocessingMLPackage pkg)
    Run the script to update the docx (eg ToC).
    void updateDocx​(WordprocessingMLPackage pkg, java.io.OutputStream outputStream)
    Run the script to update the docx (eg ToC).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Documents4jLocalServices

      public Documents4jLocalServices()
      Configure the converter with default settings.
    • Documents4jLocalServices

      public Documents4jLocalServices​(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 than maximumPoolSize, 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

      public static Exporter<Documents4jConversionSettings> getInstance()
    • export

      public void export​(Documents4jConversionSettings conversionSettings, java.io.OutputStream outputStream) throws Docx4JException
      Export to outputStream as PDF. Make sure you have setOpcPackage in conversionSettings. That's the only value which matters to documents4j.
      Specified by:
      export in interface Exporter<Documents4jConversionSettings>
      Throws:
      Docx4JException
    • export

      public void export​(OpcPackage pkg, java.io.OutputStream outputStream) throws Docx4JException
      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 Docx4JException
      Export 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 Docx4JException
      Export 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 Docx4JException
      Export 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 Docx4JException
      Run the script to update the docx (eg ToC). See class Javadoc for how to configure your script. Documents4j writes a new docx file to outputStream.
      Parameters:
      pkg -
      outputStream -
      Throws:
      Docx4JException
    • updateDocx

      Run the script to update the docx (eg ToC). See class Javadoc for how to configure your script. Returns a new WordprocessingMLPackage.
      Parameters:
      pkg -
      Returns:
      Throws:
      Docx4JException
    • updateDocx

      public void updateDocx​(java.io.File officeFile, java.io.OutputStream target) throws Docx4JException
      Run the script to update the docx (eg ToC). See class Javadoc for how to configure your script.
      Parameters:
      officeFile -
      target -
      documentType -
      Throws:
      Docx4JException
    • importAsDocx

      public void importAsDocx​(java.io.File officeFile, java.io.OutputStream target) throws Docx4JException
      Import as a docx from one of the other file types supported by Word.
      Parameters:
      officeFile -
      target -
      documentType -
      Throws:
      Docx4JException
    • importAsDocx

      public WordprocessingMLPackage importAsDocx​(java.io.File officeFile) throws Docx4JException
      Import as a docx from one of the other file types supported by Word.
      Parameters:
      officeFile -
      Throws:
      Docx4JException