Converter

Inheritance: java.lang.Object

public class Converter

Represents a group of methods intended to convert a variety of different types of documents using a single line of code.

Remarks:

The specified input and output files or streams, along with the desired save format, are used to convert the given input document of the one format into the output document of the other specified format.

The convert functionality supports over 35+ different file formats.

The convertToImages(java.lang.String, java.lang.String) group of methods are designed to transform documents into images, with each page being converted into a separate image file. These methods also convert PDF documents directly to fixed-page formats without loading them into the document model, which enhances both performance and accuracy.

With ImageSaveOptions.getPageSet() / ImageSaveOptions.setPageSet(com.aspose.words.PageSet), you can specify a particular set of pages to convert into images.

Methods

MethodDescription
convert(InputStream inputStream, LoadOptions loadOptions, OutputStream outputStream, SaveOptions saveOptions)
convert(InputStream inputStream, OutputStream outputStream, SaveOptions saveOptions)
convert(InputStream inputStream, OutputStream outputStream, int saveFormat)
convert(String inputFile, LoadOptions loadOptions, String outputFile, SaveOptions saveOptions)Converts the given input document into the output document using specified input output file names its load/save options.
convert(String inputFile, String outputFile)Converts the given input document into the output document using specified input output file names and its extensions.
convert(String inputFile, String outputFile, SaveOptions saveOptions)Converts the given input document into the output document using specified input output file names and save options.
convert(String inputFile, String outputFile, int saveFormat)
convertToImages(Document doc, ImageSaveOptions saveOptions)Converts the pages of the specified document to images using the specified save options and returns an array of streams containing the images.
convertToImages(Document doc, int saveFormat)
convertToImages(InputStream inputStream, ImageSaveOptions saveOptions)Converts the pages of the specified input stream to images using the specified save options and returns an array of streams containing the images.
convertToImages(InputStream inputStream, LoadOptions loadOptions, ImageSaveOptions saveOptions)Converts the pages of the specified input stream to images using the provided load and save options, and returns an array of streams containing the images.
convertToImages(InputStream inputStream, int saveFormat)
convertToImages(String inputFile, ImageSaveOptions saveOptions)Converts the pages of the specified input file to images using the specified save options and returns an array of streams containing the images.
convertToImages(String inputFile, LoadOptions loadOptions, String outputFile, ImageSaveOptions saveOptions)Converts the pages of the specified input file to image files using the provided load and save options.
convertToImages(String inputFile, int saveFormat)
convertToImages(String inputFile, String outputFile)Converts the pages of the specified input file to image files.
convertToImages(String inputFile, String outputFile, ImageSaveOptions saveOptions)Converts the pages of the specified input file to image files using the specified save options.
convertToImages(String inputFile, String outputFile, int saveFormat)

convert(InputStream inputStream, LoadOptions loadOptions, OutputStream outputStream, SaveOptions saveOptions)

public static void convert(InputStream inputStream, LoadOptions loadOptions, OutputStream outputStream, SaveOptions saveOptions)

Parameters:

ParameterTypeDescription
inputStreamjava.io.InputStream
loadOptionsLoadOptions
outputStreamjava.io.OutputStream
saveOptionsSaveOptions

convert(InputStream inputStream, OutputStream outputStream, SaveOptions saveOptions)

public static void convert(InputStream inputStream, OutputStream outputStream, SaveOptions saveOptions)

Parameters:

ParameterTypeDescription
inputStreamjava.io.InputStream
outputStreamjava.io.OutputStream
saveOptionsSaveOptions

convert(InputStream inputStream, OutputStream outputStream, int saveFormat)

public static void convert(InputStream inputStream, OutputStream outputStream, int saveFormat)

Parameters:

ParameterTypeDescription
inputStreamjava.io.InputStream
outputStreamjava.io.OutputStream
saveFormatint

convert(String inputFile, LoadOptions loadOptions, String outputFile, SaveOptions saveOptions)

public static void convert(String inputFile, LoadOptions loadOptions, String outputFile, SaveOptions saveOptions)

Converts the given input document into the output document using specified input output file names its load/save options.

Parameters:

ParameterTypeDescription
inputFilejava.lang.StringThe input file name.
loadOptionsLoadOptionsThe input document load options.
outputFilejava.lang.StringThe output file name.
saveOptionsSaveOptionsThe save options.

convert(String inputFile, String outputFile)

public static void convert(String inputFile, String outputFile)

Converts the given input document into the output document using specified input output file names and its extensions.

Examples:

Shows how to convert documents with a single line of code.


 Converter.convert(getMyDir() + "Document.docx", getArtifactsDir() + "LowCode.Convert.pdf");

 Converter.convert(getMyDir() + "Document.docx", getArtifactsDir() + "LowCode.Convert.rtf", SaveFormat.RTF);

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setPassword("Aspose.Words"); }
 Converter.convert(getMyDir() + "Document.doc", getArtifactsDir() + "LowCode.Convert.docx", saveOptions);
 

Parameters:

ParameterTypeDescription
inputFilejava.lang.StringThe input file name.
outputFilejava.lang.StringThe output file name.

convert(String inputFile, String outputFile, SaveOptions saveOptions)

public static void convert(String inputFile, String outputFile, SaveOptions saveOptions)

Converts the given input document into the output document using specified input output file names and save options.

Examples:

Shows how to convert documents with a single line of code.


 Converter.convert(getMyDir() + "Document.docx", getArtifactsDir() + "LowCode.Convert.pdf");

 Converter.convert(getMyDir() + "Document.docx", getArtifactsDir() + "LowCode.Convert.rtf", SaveFormat.RTF);

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setPassword("Aspose.Words"); }
 Converter.convert(getMyDir() + "Document.doc", getArtifactsDir() + "LowCode.Convert.docx", saveOptions);
 

Parameters:

ParameterTypeDescription
inputFilejava.lang.StringThe input file name.
outputFilejava.lang.StringThe output file name.
saveOptionsSaveOptionsThe save options.

convert(String inputFile, String outputFile, int saveFormat)

public static void convert(String inputFile, String outputFile, int saveFormat)

Parameters:

ParameterTypeDescription
inputFilejava.lang.String
outputFilejava.lang.String
saveFormatint

convertToImages(Document doc, ImageSaveOptions saveOptions)

public static InputStream[] convertToImages(Document doc, ImageSaveOptions saveOptions)

Converts the pages of the specified document to images using the specified save options and returns an array of streams containing the images.

Examples:

Shows how to convert document to images stream.


 InputStream[] streams = Converter.convertToImages(getMyDir() + "Big document.docx", SaveFormat.PNG);

 ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
 imageSaveOptions.setPageSet(new PageSet(1));
 streams = Converter.convertToImages(getMyDir() + "Big document.docx", imageSaveOptions);

 streams = Converter.convertToImages(new Document(getMyDir() + "Big document.docx"), SaveFormat.PNG);

 streams = Converter.convertToImages(new Document(getMyDir() + "Big document.docx"), imageSaveOptions);
 

Parameters:

ParameterTypeDescription
docDocumentThe input document.
saveOptionsImageSaveOptionsImage save options.

Returns: java.io.InputStream[] - Returns array of image streams. The streams should be disposed by the enduser.

convertToImages(Document doc, int saveFormat)

public static InputStream[] convertToImages(Document doc, int saveFormat)

Parameters:

ParameterTypeDescription
docDocument
saveFormatint

Returns: java.io.InputStream[]

convertToImages(InputStream inputStream, ImageSaveOptions saveOptions)

public static InputStream[] convertToImages(InputStream inputStream, ImageSaveOptions saveOptions)

Converts the pages of the specified input stream to images using the specified save options and returns an array of streams containing the images.

Examples:

Shows how to convert document to images from stream.


 try (FileInputStream streamIn = new FileInputStream(getMyDir() + "Big document.docx"))
 {
     InputStream[] streams = Converter.convertToImages(streamIn, SaveFormat.JPEG);

     ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
     imageSaveOptions.setPageSet(new PageSet(1));
     streams = Converter.convertToImages(streamIn, imageSaveOptions);
 }
 

Parameters:

ParameterTypeDescription
inputStreamjava.io.InputStreamThe input stream.
saveOptionsImageSaveOptionsImage save options.

Returns: java.io.InputStream[] - Returns array of image streams. The streams should be disposed by the enduser.

convertToImages(InputStream inputStream, LoadOptions loadOptions, ImageSaveOptions saveOptions)

public static InputStream[] convertToImages(InputStream inputStream, LoadOptions loadOptions, ImageSaveOptions saveOptions)

Converts the pages of the specified input stream to images using the provided load and save options, and returns an array of streams containing the images.

Parameters:

ParameterTypeDescription
inputStreamjava.io.InputStreamThe input stream.
loadOptionsLoadOptionsThe input document load options.
saveOptionsImageSaveOptionsImage save options.

Returns: java.io.InputStream[] - Returns array of image streams. The streams should be disposed by the enduser.

convertToImages(InputStream inputStream, int saveFormat)

public static InputStream[] convertToImages(InputStream inputStream, int saveFormat)

Parameters:

ParameterTypeDescription
inputStreamjava.io.InputStream
saveFormatint

Returns: java.io.InputStream[]

convertToImages(String inputFile, ImageSaveOptions saveOptions)

public static InputStream[] convertToImages(String inputFile, ImageSaveOptions saveOptions)

Converts the pages of the specified input file to images using the specified save options and returns an array of streams containing the images.

Examples:

Shows how to convert document to images stream.


 InputStream[] streams = Converter.convertToImages(getMyDir() + "Big document.docx", SaveFormat.PNG);

 ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
 imageSaveOptions.setPageSet(new PageSet(1));
 streams = Converter.convertToImages(getMyDir() + "Big document.docx", imageSaveOptions);

 streams = Converter.convertToImages(new Document(getMyDir() + "Big document.docx"), SaveFormat.PNG);

 streams = Converter.convertToImages(new Document(getMyDir() + "Big document.docx"), imageSaveOptions);
 

Parameters:

ParameterTypeDescription
inputFilejava.lang.StringThe input file name.
saveOptionsImageSaveOptionsImage save options.

Returns: java.io.InputStream[] - Returns array of image streams. The streams should be disposed by the enduser.

convertToImages(String inputFile, LoadOptions loadOptions, String outputFile, ImageSaveOptions saveOptions)

public static void convertToImages(String inputFile, LoadOptions loadOptions, String outputFile, ImageSaveOptions saveOptions)

Converts the pages of the specified input file to image files using the provided load and save options.

Parameters:

ParameterTypeDescription
inputFilejava.lang.StringThe input file name.
loadOptionsLoadOptionsThe input document load options.
outputFilejava.lang.StringThe output file name used to generate file name for page images using rule “outputFile_pageIndex.extension”
saveOptionsImageSaveOptionsImage save options.

convertToImages(String inputFile, int saveFormat)

public static InputStream[] convertToImages(String inputFile, int saveFormat)

Parameters:

ParameterTypeDescription
inputFilejava.lang.String
saveFormatint

Returns: java.io.InputStream[]

convertToImages(String inputFile, String outputFile)

public static void convertToImages(String inputFile, String outputFile)

Converts the pages of the specified input file to image files.

Examples:

Shows how to convert document to images.


 Converter.convertToImages(getMyDir() + "Big document.docx", getArtifactsDir() + "LowCode.ConvertToImages.png");

 Converter.convertToImages(getMyDir() + "Big document.docx", getArtifactsDir() + "LowCode.ConvertToImages.jpeg", SaveFormat.JPEG);

 ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
 imageSaveOptions.setPageSet(new PageSet(1));
 Converter.convertToImages(getMyDir() + "Big document.docx", getArtifactsDir() + "LowCode.ConvertToImages.png", imageSaveOptions);
 

Parameters:

ParameterTypeDescription
inputFilejava.lang.StringThe input file name.
outputFilejava.lang.StringThe output file name used to generate file name for page images using rule “outputFile_pageIndex.extension”

convertToImages(String inputFile, String outputFile, ImageSaveOptions saveOptions)

public static void convertToImages(String inputFile, String outputFile, ImageSaveOptions saveOptions)

Converts the pages of the specified input file to image files using the specified save options.

Examples:

Shows how to convert document to images.


 Converter.convertToImages(getMyDir() + "Big document.docx", getArtifactsDir() + "LowCode.ConvertToImages.png");

 Converter.convertToImages(getMyDir() + "Big document.docx", getArtifactsDir() + "LowCode.ConvertToImages.jpeg", SaveFormat.JPEG);

 ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
 imageSaveOptions.setPageSet(new PageSet(1));
 Converter.convertToImages(getMyDir() + "Big document.docx", getArtifactsDir() + "LowCode.ConvertToImages.png", imageSaveOptions);
 

Parameters:

ParameterTypeDescription
inputFilejava.lang.StringThe input file name.
outputFilejava.lang.StringThe output file name used to generate file name for page images using rule “outputFile_pageIndex.extension”
saveOptionsImageSaveOptionsImage save options.

convertToImages(String inputFile, String outputFile, int saveFormat)

public static void convertToImages(String inputFile, String outputFile, int saveFormat)

Parameters:

ParameterTypeDescription
inputFilejava.lang.String
outputFilejava.lang.String
saveFormatint