public class DocumentConverter extends Object
convertToFile()
or the
convertToStream()
methods. You can specify format-specific setting by
passing a derived instance of a EncoderSettings
. The
ConversionMode
parameter lets you specify how to use the input
documents in the conversion. You can specify the input pages and their order
using a PageRangeSettings
instance. When you are converting multiple
documents, the page range settings for those documents can be specified by
setting the inputDocPageRangeSettings
parameter with a list of
PageRangeSettings
instances, each one corresponding to the input
document with the same index. Use the ConverterPreferences
object to specify
password
and
digitization
(
image-enhancement
, OCR
,
digitizable elements
) settings. Implement
ConverterListener
or derive
from ConverterListenerAdapter
to get notified of events in the
conversion process.
DocumentConverter dc = new DocumentConverter(); try { dc.convertToFile("./sample.docx", "./sample.pdf"); } catch (FormatNotSupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ConverterException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XDocException e) { // TODO Auto-generated catch block e.printStackTrace(); }
PDFEncoderSettings
specify PDF-conversion settings. You can also
convert multiple PDF documents to a single PDF portfolio by using the
PDFPortfolioSettings
object returned by
the PDFEncoderSettings.getPortfolioSettings()
method.
import java.util.ArrayList; import com.gnostice.core.XDocException; import com.gnostice.documents.ConverterException; import com.gnostice.documents.DocumentConverter; import com.gnostice.documents.FormatNotSupportedException; import com.gnostice.documents.PageRangeSettings; import com.gnostice.documents.enums.ConversionMode; import com.gnostice.documents.pdf.PDFEncoderSettings; import com.gnostice.documents.pdf.PortfolioCreationMode; import com.gnostice.documents.pdf.PortfolioLayoutMode; public class PDFPortfolioCreationDemo { static { XDocSetup.activate(); } public static void main(String[] args) { // Create a document converter instance DocumentConverter dc = new DocumentConverter(); // Specify input files ArrayList oInputPDFsList = new ArrayList(); oInputPDFsList.add("intel-adrenaline.pdf"); oInputPDFsList.add("SampleLetterToYourSenator.docx"); oInputPDFsList.add("Blue hills.jpg"); oInputPDFsList.add("hebrew-rtl-test.txt"); // Create PDF encoding settings PDFEncoderSettings pes = new PDFEncoderSettings(); // Automatically show document previews in a side panel // in viewer application such as Adobe Reader pes.getPortfolioSettings().setPortfolioCreationMode( PortfolioCreationMode.ALWAYS); pes.getPortfolioSettings().setLayoutMode(PortfolioLayoutMode.TILE); // Create page range settings ArrayList oPageRangeSettingsList = new ArrayList(); // Include all pages from all input documents oPageRangeSettingsList.add(new PageRangeSettings("-")); try { // Create a PDF portfolio dc.convertToFile( // documents to be included in portfolio oInputPDFsList, // mime type (PDF) "application/pdf", // output directory (current directory) ".", // output file prefix "PortFolio1", // PDF encoder settings pes, // conversion mode ConversionMode.CREATE_NEW_FILE_AND_ATTACH_ALL_AS_ORIGINAL, // password (empty) "", // page ranges (all pages from all documents) oPageRangeSettingsList); } catch (FormatNotSupportedException e) { e.printStackTrace(); } catch (ConverterException e) { e.printStackTrace(); } catch (XDocException e) { e.printStackTrace(); } } }
Constructor and Description |
---|
DocumentConverter()
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
void |
addConverterListener(ConverterListener converterListener)
Sets specified user class instance to be notified of events in document
conversion jobs.
|
List<String> |
convertToFile(Object input,
String outputMIMEType,
String outputDir,
String baseFileName,
EncoderSettings encoderSettings,
boolean mergeAfterConvert,
Object inputDocPassword,
Object inputDocPageRangeSettings)
Deprecated.
Intead use
convertToFile method that accepts ConversionMode
parameter instead of mergeAfterConvert parameter. |
List<String> |
convertToFile(Object input,
String outputMIMEType,
String outputDir,
String baseFileName,
EncoderSettings encoderSettings,
ConversionMode conversionMode,
Object inputDocPassword,
Object inputDocPageRangeSettings)
Converts specified input files to specified format and create the output
documents in the specified directory.
|
void |
convertToFile(String inputFileName,
String outputFileName)
Converts specified input document to specified output document.
|
void |
convertToFile(String inputFileName,
String outputFileName,
EncoderSettings encoderSettings,
String inputDocPassword,
PageRangeSettings inputDocPageRangeSettings)
Converts specified document to specified output file using specified
settings.
|
List<OutputStream> |
convertToStream(Object input,
String outputMIMEType,
EncoderSettings encoderSettings,
boolean mergeAfterConvert,
Object inputDocPassword,
Object inputDocPageRangeSettings)
Deprecated.
Instead use
convertToStream method that accepts ConversionMode
parameter instead of mergeAfterConvert parameter. |
List<OutputStream> |
convertToStream(Object input,
String outputMIMEType,
EncoderSettings encoderSettings,
ConversionMode conversionMode,
Object inputDocPassword,
Object inputDocPageRangeSettings)
Converts documents in specified list of streams to
|
ConverterListener[] |
getConverterListeners()
Returns a list of user class instances that will be notified of document
conversion events.
|
ConverterPreferences |
getPreferences()
Returns current conversion settings such as those for input page ranges,
password and digitization.
|
ConverterListener |
removeConverterListener(ConverterListener converterListener)
Stops specified user class instance from receiving notifications of
document conversion events.
|
public DocumentConverter()
public ConverterPreferences getPreferences()
public void convertToFile(String inputFileName, String outputFileName) throws FormatNotSupportedException, ConverterException, XDocException
inputFileName
- pathname of the input documentoutputFileName
- pathname of the output documentFormatNotSupportedException
- if the format specified is not supportedConverterException
- if an error is encountered when converting the documentXDocException
- if an error is encountered in document processingXDocException
public void convertToFile(String inputFileName, String outputFileName, EncoderSettings encoderSettings, String inputDocPassword, PageRangeSettings inputDocPageRangeSettings) throws FormatNotSupportedException, ConverterException, XDocException
inputFileName
- pathname of the input documentoutputFileName
- pathname of the output documentencoderSettings
- format settings for the output documentinputDocPassword
- password to decrypt the input documentinputDocPageRangeSettings
- list containing page ranges
of input documentsFormatNotSupportedException
- if the format for the output document is not supportedConverterException
- if an error is encountered when converting the documentXDocException
- if an error is encountered in document processingXDocException
public List<String> convertToFile(Object input, String outputMIMEType, String outputDir, String baseFileName, EncoderSettings encoderSettings, boolean mergeAfterConvert, Object inputDocPassword, Object inputDocPageRangeSettings) throws FormatNotSupportedException, ConverterException, XDocException
convertToFile
method that accepts ConversionMode
parameter instead of mergeAfterConvert parameter.public List<String> convertToFile(Object input, String outputMIMEType, String outputDir, String baseFileName, EncoderSettings encoderSettings, ConversionMode conversionMode, Object inputDocPassword, Object inputDocPageRangeSettings) throws FormatNotSupportedException, ConverterException, XDocException
input
- list containing pathnames or streams of input documents that need
to be convertedoutputMIMEType
- mime type identifying the output document formatoutputDir
- pathname of the directory where the output documents need to be
createdbaseFileName
- prefix of the output documentsencoderSettings
- format settings for the output documentconversionMode
- how the specified input documents need to be convertedinputDocPassword
- list containing the passwords to decrypt the input documentsinputDocPageRangeSettings
- list containing page ranges
of input
documentsFormatNotSupportedException
- if the format for the output document is not supportedConverterException
- if an error is encountered when converting the documentXDocException
- if an error is encountered in document processingXDocException
public List<OutputStream> convertToStream(Object input, String outputMIMEType, EncoderSettings encoderSettings, boolean mergeAfterConvert, Object inputDocPassword, Object inputDocPageRangeSettings) throws FormatNotSupportedException, ConverterException, XDocException
convertToStream
method that accepts ConversionMode
parameter instead of mergeAfterConvert parameter.public List<OutputStream> convertToStream(Object input, String outputMIMEType, EncoderSettings encoderSettings, ConversionMode conversionMode, Object inputDocPassword, Object inputDocPageRangeSettings) throws FormatNotSupportedException, ConverterException, XDocException
input
- list containing pathnames or streams of input documents that need
to be convertedoutputMIMEType
- mime type identifying the output document formatencoderSettings
- format settings for the output documentconversionMode
- how the specified input documents need to be convertedinputDocPassword
- list containing the passwords to decrypt the input documentsinputDocPageRangeSettings
- list containing page ranges
of input documentsFormatNotSupportedException
- if the format for the output document is not supportedConverterException
- if an error is encountered when converting the documentXDocException
- if an error is encountered in document processingXDocException
public void addConverterListener(ConverterListener converterListener)
converterListener
- user class instance which needs to be notified of document
conversion eventspublic ConverterListener removeConverterListener(ConverterListener converterListener)
converterListener
- user class instance which should not be receiving notifications of
document conversion eventspublic ConverterListener[] getConverterListeners()