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
convert(InputStream inputStream, LoadOptions loadOptions, OutputStream outputStream, SaveOptions saveOptions)
public static void convert(InputStream inputStream, LoadOptions loadOptions, OutputStream outputStream, SaveOptions saveOptions)
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | |
loadOptions | LoadOptions | |
outputStream | java.io.OutputStream | |
saveOptions | SaveOptions |
convert(InputStream inputStream, OutputStream outputStream, SaveOptions saveOptions)
public static void convert(InputStream inputStream, OutputStream outputStream, SaveOptions saveOptions)
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | |
outputStream | java.io.OutputStream | |
saveOptions | SaveOptions |
convert(InputStream inputStream, OutputStream outputStream, int saveFormat)
public static void convert(InputStream inputStream, OutputStream outputStream, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | |
outputStream | java.io.OutputStream | |
saveFormat | int |
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:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
loadOptions | LoadOptions | The input document load options. |
outputFile | java.lang.String | The output file name. |
saveOptions | SaveOptions | The 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:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
outputFile | java.lang.String | The 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:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
outputFile | java.lang.String | The output file name. |
saveOptions | SaveOptions | The save options. |
convert(String inputFile, String outputFile, int saveFormat)
public static void convert(String inputFile, String outputFile, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | |
outputFile | java.lang.String | |
saveFormat | int |
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:
Parameter | Type | Description |
---|---|---|
doc | Document | The input document. |
saveOptions | ImageSaveOptions | Image 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:
Parameter | Type | Description |
---|---|---|
doc | Document | |
saveFormat | int |
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:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | The input stream. |
saveOptions | ImageSaveOptions | Image 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:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | The input stream. |
loadOptions | LoadOptions | The input document load options. |
saveOptions | ImageSaveOptions | Image 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:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | |
saveFormat | int |
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:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
saveOptions | ImageSaveOptions | Image 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:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
loadOptions | LoadOptions | The input document load options. |
outputFile | java.lang.String | The output file name used to generate file name for page images using rule “outputFile_pageIndex.extension” |
saveOptions | ImageSaveOptions | Image save options. |
convertToImages(String inputFile, int saveFormat)
public static InputStream[] convertToImages(String inputFile, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | |
saveFormat | int |
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:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
outputFile | java.lang.String | The 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:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
outputFile | java.lang.String | The output file name used to generate file name for page images using rule “outputFile_pageIndex.extension” |
saveOptions | ImageSaveOptions | Image save options. |
convertToImages(String inputFile, String outputFile, int saveFormat)
public static void convertToImages(String inputFile, String outputFile, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | |
outputFile | java.lang.String | |
saveFormat | int |