com.aspose.words
Class Converter

java.lang.Object
    extended by com.aspose.words.Converter

public abstract class Converter 
extends java.lang.Object

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

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 (using our pdf2word plugin), which enhances both performance and accuracy.

With ImageSaveOptions.PageSet, you can specify a particular set of pages to convert into images.


Method Summary
static voidconvert(java.lang.String inputFile, java.lang.String outputFile)
           Converts the given input document into the output document using specified input output file names and its extensions.
static voidconvert(java.lang.String inputFile, java.lang.String outputFile, SaveOptions saveOptions)
           Converts the given input document into the output document using specified input output file names and save options.
static voidconvert(java.lang.String inputFile, java.lang.String outputFile, int saveFormat)
           Converts the given input document into the output document using specified input output file names and the final document format.
static System.IO.Stream[]convertToImages(Document doc, ImageSaveOptions saveOptions)
           Converts the document pages to images.
static System.IO.Stream[]convertToImages(Document doc, int saveFormat)
           Converts the document pages to images.
static System.IO.Stream[]convertToImages(java.lang.String inputFile, ImageSaveOptions saveOptions)
           Converts the input file pages to images.
static System.IO.Stream[]convertToImages(java.lang.String inputFile, int saveFormat)
           Converts the input file pages to images.
static voidconvertToImages(java.lang.String inputFile, java.lang.String outputFile)
           Converts the input file pages to images.
static voidconvertToImages(java.lang.String inputFile, java.lang.String outputFile, ImageSaveOptions saveOptions)
           Converts the input file pages to images.
static voidconvertToImages(java.lang.String inputFile, java.lang.String outputFile, int saveFormat)
           Converts the input file pages to images.
 

Method Detail

convert

public static void convert(java.lang.String inputFile, java.lang.String outputFile)
                        throws java.lang.Exception
Converts the given input document into the output document using specified input output file names and its extensions.
Parameters:
inputFile - The input file name.
outputFile - The output file name.

Example:

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);

convert

public static void convert(java.lang.String inputFile, java.lang.String outputFile, SaveOptions saveOptions)
                        throws java.lang.Exception
Converts the given input document into the output document using specified input output file names and save options.
Parameters:
inputFile - The input file name.
outputFile - The output file name.
saveOptions - The save options.

Example:

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);

convert

public static void convert(java.lang.String inputFile, java.lang.String outputFile, int saveFormat)
                        throws java.lang.Exception
Converts the given input document into the output document using specified input output file names and the final document format.
Parameters:
inputFile - The input file name.
outputFile - The output file name.
saveFormat - A SaveFormat value. The save format.

Example:

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);

convertToImages

public static System.IO.Stream[] convertToImages(Document doc, ImageSaveOptions saveOptions)
                                    throws java.lang.Exception
Converts the document pages to images.
Parameters:
doc - The input document.
saveOptions - Image save options.
Returns:
Returns array of image streams. The streams should be disposed by the enduser.

Example:

Shows how to convert document to images stream.
Stream[] 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);

convertToImages

public static System.IO.Stream[] convertToImages(Document doc, int saveFormat)
                                    throws java.lang.Exception
Converts the document pages to images.
Parameters:
doc - The input document.
saveFormat - A SaveFormat value. Save format. Only image save formats are allowed.
Returns:
Returns array of image streams. The streams should be disposed by the enduser.

Example:

Shows how to convert document to images stream.
Stream[] 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);

convertToImages

public static System.IO.Stream[] convertToImages(java.lang.String inputFile, ImageSaveOptions saveOptions)
                                    throws java.lang.Exception
Converts the input file pages to images.
Parameters:
inputFile - The input file name.
saveOptions - Image save options.
Returns:
Returns array of image streams. The streams should be disposed by the enduser.

Example:

Shows how to convert document to images stream.
Stream[] 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);

convertToImages

public static System.IO.Stream[] convertToImages(java.lang.String inputFile, int saveFormat)
                                    throws java.lang.Exception
Converts the input file pages to images.
Parameters:
inputFile - The input file name.
saveFormat - A SaveFormat value. Save format. Only image save formats are allowed.
Returns:
Returns array of image streams. The streams should be disposed by the enduser.

Example:

Shows how to convert document to images stream.
Stream[] 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);

convertToImages

public static void convertToImages(java.lang.String inputFile, java.lang.String outputFile)
                                throws java.lang.Exception
Converts the input file pages to images.
Parameters:
inputFile - The input file name.
outputFile - The output file name used to generate file name for page images using rule "outputFile_pageIndex.extension"

Example:

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);

convertToImages

public static void convertToImages(java.lang.String inputFile, java.lang.String outputFile, ImageSaveOptions saveOptions)
                                throws java.lang.Exception
Converts the input file pages to images.
Parameters:
inputFile - The input file name.
outputFile - The output file name used to generate file name for page images using rule "outputFile_pageIndex.extension"
saveOptions - Image save options.

Example:

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);

convertToImages

public static void convertToImages(java.lang.String inputFile, java.lang.String outputFile, int saveFormat)
                                throws java.lang.Exception
Converts the input file pages to images.
Parameters:
inputFile - The input file name.
outputFile - The output file name used to generate file name for page images using rule "outputFile_pageIndex.extension"
saveFormat - A SaveFormat value. Save format. Only image save formats are allowed.

Example:

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);

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.