Converter

Inheritance: java.lang.Object, com.aspose.words.Processor

public class Converter extends Processor

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 M:Aspose.Words.LowCode.Converter.ConvertToImages(System.String,Aspose.Words.SaveFormat) 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)
create()Creates new instance of the converter processor.
create(ConverterContext context)Creates new instance of the converter processor.
execute()Execute the processor action.
from(InputStream input)
from(InputStream input, LoadOptions loadOptions)Specifies input document for processing.
from(String input)
from(String input, LoadOptions loadOptions)Specifies input document for processing.
to(OutputStream output, SaveOptions saveOptions)
to(OutputStream output, int saveFormat)
to(String output)
to(String output, SaveOptions saveOptions)Specifies output file for the processor.
to(String output, int saveFormat)
to(ArrayList output, SaveOptions saveOptions)
to(ArrayList output, int saveFormat)
toOutput(ArrayList output, SaveOptions saveOptions)
toOutput(ArrayList output, 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.

Remarks:

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

Examples:

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


 String doc = getMyDir() + "Document.docx";

 Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.pdf");

 Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.SaveFormat.rtf", SaveFormat.RTF);

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
 {
     saveOptions.setPassword("Aspose.Words");
 }
 LoadOptions loadOptions = new LoadOptions();
 {
     loadOptions.setIgnoreOleData(true);
 }
 Converter.convert(doc, loadOptions, getArtifactsDir() + "LowCode.Convert.LoadOptions.docx", saveOptions);

 Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.SaveOptions.docx", saveOptions);
 

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.

Remarks:

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

Examples:

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


 String doc = getMyDir() + "Document.docx";

 Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.pdf");

 Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.SaveFormat.rtf", SaveFormat.RTF);

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
 {
     saveOptions.setPassword("Aspose.Words");
 }
 LoadOptions loadOptions = new LoadOptions();
 {
     loadOptions.setIgnoreOleData(true);
 }
 Converter.convert(doc, loadOptions, getArtifactsDir() + "LowCode.Convert.LoadOptions.docx", saveOptions);

 Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.SaveOptions.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.

Remarks:

If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.

If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.

Examples:

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


 String doc = getMyDir() + "Document.docx";

 Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.pdf");

 Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.SaveFormat.rtf", SaveFormat.RTF);

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
 {
     saveOptions.setPassword("Aspose.Words");
 }
 LoadOptions loadOptions = new LoadOptions();
 {
     loadOptions.setIgnoreOleData(true);
 }
 Converter.convert(doc, loadOptions, getArtifactsDir() + "LowCode.Convert.LoadOptions.docx", saveOptions);

 Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.SaveOptions.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 OutputStream[] 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.


 String doc = getMyDir() + "Big document.docx";

 OutputStream[] streams = Converter.convertToImages(doc, SaveFormat.PNG);

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

 streams = Converter.convertToImages(new Document(doc), SaveFormat.PNG);

 streams = Converter.convertToImages(new Document(doc), imageSaveOptions);
 

Parameters:

ParameterTypeDescription
docDocumentThe input document.
saveOptionsImageSaveOptionsImage save options.

Returns: java.io.OutputStream[] - Returns array of image streams. The streams should be disposed by the end user.

convertToImages(Document doc, int saveFormat)

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

Parameters:

ParameterTypeDescription
docDocument
saveFormatint

Returns: java.io.OutputStream[]

convertToImages(InputStream inputStream, ImageSaveOptions saveOptions)

public static OutputStream[] 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")) {
     OutputStream[] streams = Converter.convertToImages(streamIn, SaveFormat.JPEG);

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

     LoadOptions loadOptions = new LoadOptions();
     {
         loadOptions.setIgnoreOleData(false);
     }
     Converter.convertToImages(streamIn, loadOptions, imageSaveOptions);
 }
 

Parameters:

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

Returns: java.io.OutputStream[] - Returns array of image streams. The streams should be disposed by the end user.

convertToImages(InputStream inputStream, LoadOptions loadOptions, ImageSaveOptions saveOptions)

public static OutputStream[] 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.

Examples:

Shows how to convert document to images from stream.


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

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

     LoadOptions loadOptions = new LoadOptions();
     {
         loadOptions.setIgnoreOleData(false);
     }
     Converter.convertToImages(streamIn, loadOptions, imageSaveOptions);
 }
 

Parameters:

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

Returns: java.io.OutputStream[] - Returns array of image streams. The streams should be disposed by the end user.

convertToImages(InputStream inputStream, int saveFormat)

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

Parameters:

ParameterTypeDescription
inputStreamjava.io.InputStream
saveFormatint

Returns: java.io.OutputStream[]

convertToImages(String inputFile, ImageSaveOptions saveOptions)

public static OutputStream[] 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.


 String doc = getMyDir() + "Big document.docx";

 OutputStream[] streams = Converter.convertToImages(doc, SaveFormat.PNG);

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

 streams = Converter.convertToImages(new Document(doc), SaveFormat.PNG);

 streams = Converter.convertToImages(new Document(doc), imageSaveOptions);
 

Parameters:

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

Returns: java.io.OutputStream[] - Returns array of image streams. The streams should be disposed by the end user.

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.

Examples:

Shows how to convert document to images.


 String doc = getMyDir() + "Big document.docx";

 Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.1.png");

 Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.2.jpeg", SaveFormat.JPEG);

 LoadOptions loadOptions = new LoadOptions();
 {
     loadOptions.setIgnoreOleData(false);
 }
 ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
 imageSaveOptions.setPageSet(new PageSet(1));
 Converter.convertToImages(doc, loadOptions, getArtifactsDir() + "LowCode.ConvertToImages.3.png", imageSaveOptions);

 Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.4.png", imageSaveOptions);
 

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 OutputStream[] convertToImages(String inputFile, int saveFormat)

Parameters:

ParameterTypeDescription
inputFilejava.lang.String
saveFormatint

Returns: java.io.OutputStream[]

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.


 String doc = getMyDir() + "Big document.docx";

 Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.1.png");

 Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.2.jpeg", SaveFormat.JPEG);

 LoadOptions loadOptions = new LoadOptions();
 {
     loadOptions.setIgnoreOleData(false);
 }
 ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
 imageSaveOptions.setPageSet(new PageSet(1));
 Converter.convertToImages(doc, loadOptions, getArtifactsDir() + "LowCode.ConvertToImages.3.png", imageSaveOptions);

 Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.4.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.


 String doc = getMyDir() + "Big document.docx";

 Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.1.png");

 Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.2.jpeg", SaveFormat.JPEG);

 LoadOptions loadOptions = new LoadOptions();
 {
     loadOptions.setIgnoreOleData(false);
 }
 ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
 imageSaveOptions.setPageSet(new PageSet(1));
 Converter.convertToImages(doc, loadOptions, getArtifactsDir() + "LowCode.ConvertToImages.3.png", imageSaveOptions);

 Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.4.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

create()

public static Converter create()

Creates new instance of the converter processor.

Returns: Converter

create(ConverterContext context)

public static Converter create(ConverterContext context)

Creates new instance of the converter processor.

Examples:

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


 String doc = getMyDir() + "Big document.docx";

 ConverterContext converterContext = new ConverterContext();

 Converter.create(converterContext)
         .from(doc)
         .to(getArtifactsDir() + "LowCode.ConvertContext.1.pdf")
         .execute();

 Converter.create(converterContext)
         .from(doc)
         .to(getArtifactsDir() + "LowCode.ConvertContext.2.pdf", SaveFormat.RTF)
         .execute();

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
 {
     saveOptions.setPassword("Aspose.Words");
 }
 LoadOptions loadOptions = new LoadOptions();
 {
     loadOptions.setIgnoreOleData(true);
 }
 Converter.create(converterContext)
         .from(doc, loadOptions)
         .to(getArtifactsDir() + "LowCode.ConvertContext.3.docx", saveOptions)
         .execute();

 Converter.create(converterContext)
         .from(doc)
         .to(getArtifactsDir() + "LowCode.ConvertContext.4.png", new ImageSaveOptions(SaveFormat.PNG))
         .execute();
 

Shows how to convert documents from a stream with a single line of code using context.


 String doc = getMyDir() + "Document.docx";
 ConverterContext converterContext = new ConverterContext();

 try (FileInputStream streamIn = new FileInputStream(doc)) {
     try (FileOutputStream streamOut = new FileOutputStream(getArtifactsDir() + "LowCode.ConvertContextStream.1.docx")) {
         Converter.create(converterContext)
                 .from(streamIn)
                 .to(streamOut, SaveFormat.RTF)
                 .execute();
     }

     OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
     {
         saveOptions.setPassword("Aspose.Words");
     }
     LoadOptions loadOptions = new LoadOptions();
     {
         loadOptions.setIgnoreOleData(true);
     }
     try (FileOutputStream streamOut1 = new FileOutputStream(getArtifactsDir() + "LowCode.ConvertContextStream.2.docx")) {
         Converter.create(converterContext)
                 .from(streamIn, loadOptions)
                 .to(streamOut1, saveOptions)
                 .execute();
     }
 }
 

Parameters:

ParameterTypeDescription
contextConverterContext

Returns: Converter

execute()

public void execute()

Execute the processor action.

Examples:

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


 String doc = getMyDir() + "Big document.docx";

 ConverterContext converterContext = new ConverterContext();

 Converter.create(converterContext)
         .from(doc)
         .to(getArtifactsDir() + "LowCode.ConvertContext.1.pdf")
         .execute();

 Converter.create(converterContext)
         .from(doc)
         .to(getArtifactsDir() + "LowCode.ConvertContext.2.pdf", SaveFormat.RTF)
         .execute();

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
 {
     saveOptions.setPassword("Aspose.Words");
 }
 LoadOptions loadOptions = new LoadOptions();
 {
     loadOptions.setIgnoreOleData(true);
 }
 Converter.create(converterContext)
         .from(doc, loadOptions)
         .to(getArtifactsDir() + "LowCode.ConvertContext.3.docx", saveOptions)
         .execute();

 Converter.create(converterContext)
         .from(doc)
         .to(getArtifactsDir() + "LowCode.ConvertContext.4.png", new ImageSaveOptions(SaveFormat.PNG))
         .execute();
 

Shows how to convert documents from a stream with a single line of code using context.


 String doc = getMyDir() + "Document.docx";
 ConverterContext converterContext = new ConverterContext();

 try (FileInputStream streamIn = new FileInputStream(doc)) {
     try (FileOutputStream streamOut = new FileOutputStream(getArtifactsDir() + "LowCode.ConvertContextStream.1.docx")) {
         Converter.create(converterContext)
                 .from(streamIn)
                 .to(streamOut, SaveFormat.RTF)
                 .execute();
     }

     OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
     {
         saveOptions.setPassword("Aspose.Words");
     }
     LoadOptions loadOptions = new LoadOptions();
     {
         loadOptions.setIgnoreOleData(true);
     }
     try (FileOutputStream streamOut1 = new FileOutputStream(getArtifactsDir() + "LowCode.ConvertContextStream.2.docx")) {
         Converter.create(converterContext)
                 .from(streamIn, loadOptions)
                 .to(streamOut1, saveOptions)
                 .execute();
     }
 }
 

Shows how to merge documents into a single output document using context.


 //There is a several ways to merge documents:
 String inputDoc1 = getMyDir() + "Big document.docx";
 String inputDoc2 = getMyDir() + "Tables.docx";

 MergerContext mergerContext = new MergerContext();
 mergerContext.setMergeFormatMode(MergeFormatMode.KEEP_SOURCE_FORMATTING);

 Merger.create(mergerContext)
         .from(inputDoc1)
         .from(inputDoc2)
         .to(getArtifactsDir() + "LowCode.MergeContextDocuments.1.docx")
         .execute();

 LoadOptions firstLoadOptions = new LoadOptions();
 {
     firstLoadOptions.setIgnoreOleData(true);
 }
 LoadOptions secondLoadOptions = new LoadOptions();
 {
     secondLoadOptions.setIgnoreOleData(false);
 }
 Merger.create(mergerContext)
         .from(inputDoc1, firstLoadOptions)
         .from(inputDoc2, secondLoadOptions)
         .to(getArtifactsDir() + "LowCode.MergeContextDocuments.2.docx", SaveFormat.DOCX)
         .execute();

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
 {
     saveOptions.setPassword("Aspose.Words");
 }
 Merger.create(mergerContext)
         .from(inputDoc1)
         .from(inputDoc2)
         .to(getArtifactsDir() + "LowCode.MergeContextDocuments.3.docx", saveOptions)
         .execute();
 

Shows how to merge documents from stream into a single output document using context.


 //There is a several ways to merge documents:
 String inputDoc1 = getMyDir() + "Big document.docx";
 String inputDoc2 = getMyDir() + "Tables.docx";

 MergerContext mergerContext = new MergerContext();
 mergerContext.setMergeFormatMode(MergeFormatMode.KEEP_SOURCE_FORMATTING);

 try (FileInputStream firstStreamIn = new FileInputStream(inputDoc1)) {
     try (FileInputStream secondStreamIn = new FileInputStream(inputDoc2)) {
         OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
         {
             saveOptions.setPassword("Aspose.Words");
         }
         try (FileOutputStream streamOut = new FileOutputStream(getArtifactsDir() + "LowCode.MergeStreamContextDocuments.1.docx")) {
             Merger.create(mergerContext)
                     .from(firstStreamIn)
                     .from(secondStreamIn)
                     .to(streamOut, saveOptions)
                     .execute();
         }

         LoadOptions firstLoadOptions = new LoadOptions();
         {
             firstLoadOptions.setIgnoreOleData(true);
         }
         LoadOptions secondLoadOptions = new LoadOptions();
         {
             secondLoadOptions.setIgnoreOleData(false);
         }
         try (FileOutputStream streamOut1 = new FileOutputStream(getArtifactsDir() + "LowCode.MergeStreamContextDocuments.2.docx")) {
             Merger.create(mergerContext)
                     .from(firstStreamIn, firstLoadOptions)
                     .from(secondStreamIn, secondLoadOptions)
                     .to(streamOut1, SaveFormat.DOCX)
                     .execute();
         }
     }
 }
 

from(InputStream input)

public Processor from(InputStream input)

Parameters:

ParameterTypeDescription
inputjava.io.InputStream

Returns: Processor

from(InputStream input, LoadOptions loadOptions)

public Processor from(InputStream input, LoadOptions loadOptions)

Specifies input document for processing.

Remarks:

If the processor accepts only one file as an input, only the last specified file will be processed. Merger processor accepts multiple files as an input, as the result all the specified documents will be merged. Converter processor accepts only one file as an input, so only the last specified file will be converted.

Examples:

Shows how to convert documents from a stream with a single line of code using context.


 String doc = getMyDir() + "Document.docx";
 ConverterContext converterContext = new ConverterContext();

 try (FileInputStream streamIn = new FileInputStream(doc)) {
     try (FileOutputStream streamOut = new FileOutputStream(getArtifactsDir() + "LowCode.ConvertContextStream.1.docx")) {
         Converter.create(converterContext)
                 .from(streamIn)
                 .to(streamOut, SaveFormat.RTF)
                 .execute();
     }

     OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
     {
         saveOptions.setPassword("Aspose.Words");
     }
     LoadOptions loadOptions = new LoadOptions();
     {
         loadOptions.setIgnoreOleData(true);
     }
     try (FileOutputStream streamOut1 = new FileOutputStream(getArtifactsDir() + "LowCode.ConvertContextStream.2.docx")) {
         Converter.create(converterContext)
                 .from(streamIn, loadOptions)
                 .to(streamOut1, saveOptions)
                 .execute();
     }
 }
 

Shows how to merge documents from stream into a single output document using context.


 //There is a several ways to merge documents:
 String inputDoc1 = getMyDir() + "Big document.docx";
 String inputDoc2 = getMyDir() + "Tables.docx";

 MergerContext mergerContext = new MergerContext();
 mergerContext.setMergeFormatMode(MergeFormatMode.KEEP_SOURCE_FORMATTING);

 try (FileInputStream firstStreamIn = new FileInputStream(inputDoc1)) {
     try (FileInputStream secondStreamIn = new FileInputStream(inputDoc2)) {
         OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
         {
             saveOptions.setPassword("Aspose.Words");
         }
         try (FileOutputStream streamOut = new FileOutputStream(getArtifactsDir() + "LowCode.MergeStreamContextDocuments.1.docx")) {
             Merger.create(mergerContext)
                     .from(firstStreamIn)
                     .from(secondStreamIn)
                     .to(streamOut, saveOptions)
                     .execute();
         }

         LoadOptions firstLoadOptions = new LoadOptions();
         {
             firstLoadOptions.setIgnoreOleData(true);
         }
         LoadOptions secondLoadOptions = new LoadOptions();
         {
             secondLoadOptions.setIgnoreOleData(false);
         }
         try (FileOutputStream streamOut1 = new FileOutputStream(getArtifactsDir() + "LowCode.MergeStreamContextDocuments.2.docx")) {
             Merger.create(mergerContext)
                     .from(firstStreamIn, firstLoadOptions)
                     .from(secondStreamIn, secondLoadOptions)
                     .to(streamOut1, SaveFormat.DOCX)
                     .execute();
         }
     }
 }
 

Parameters:

ParameterTypeDescription
inputjava.io.InputStreamInput document stream.
loadOptionsLoadOptionsOptional load options used to load the document.

Returns: Processor - Returns processor with specified input file stream.

from(String input)

public Processor from(String input)

Parameters:

ParameterTypeDescription
inputjava.lang.String

Returns: Processor

from(String input, LoadOptions loadOptions)

public Processor from(String input, LoadOptions loadOptions)

Specifies input document for processing.

Remarks:

If the processor accepts only one file as an input, only the last specified file will be processed. Merger processor accepts multiple files as an input, as the result all the specified documents will be merged. Converter processor accepts only one file as an input, so only the last specified file will be converted.

Examples:

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


 String doc = getMyDir() + "Big document.docx";

 ConverterContext converterContext = new ConverterContext();

 Converter.create(converterContext)
         .from(doc)
         .to(getArtifactsDir() + "LowCode.ConvertContext.1.pdf")
         .execute();

 Converter.create(converterContext)
         .from(doc)
         .to(getArtifactsDir() + "LowCode.ConvertContext.2.pdf", SaveFormat.RTF)
         .execute();

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
 {
     saveOptions.setPassword("Aspose.Words");
 }
 LoadOptions loadOptions = new LoadOptions();
 {
     loadOptions.setIgnoreOleData(true);
 }
 Converter.create(converterContext)
         .from(doc, loadOptions)
         .to(getArtifactsDir() + "LowCode.ConvertContext.3.docx", saveOptions)
         .execute();

 Converter.create(converterContext)
         .from(doc)
         .to(getArtifactsDir() + "LowCode.ConvertContext.4.png", new ImageSaveOptions(SaveFormat.PNG))
         .execute();
 

Shows how to merge documents into a single output document using context.


 //There is a several ways to merge documents:
 String inputDoc1 = getMyDir() + "Big document.docx";
 String inputDoc2 = getMyDir() + "Tables.docx";

 MergerContext mergerContext = new MergerContext();
 mergerContext.setMergeFormatMode(MergeFormatMode.KEEP_SOURCE_FORMATTING);

 Merger.create(mergerContext)
         .from(inputDoc1)
         .from(inputDoc2)
         .to(getArtifactsDir() + "LowCode.MergeContextDocuments.1.docx")
         .execute();

 LoadOptions firstLoadOptions = new LoadOptions();
 {
     firstLoadOptions.setIgnoreOleData(true);
 }
 LoadOptions secondLoadOptions = new LoadOptions();
 {
     secondLoadOptions.setIgnoreOleData(false);
 }
 Merger.create(mergerContext)
         .from(inputDoc1, firstLoadOptions)
         .from(inputDoc2, secondLoadOptions)
         .to(getArtifactsDir() + "LowCode.MergeContextDocuments.2.docx", SaveFormat.DOCX)
         .execute();

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
 {
     saveOptions.setPassword("Aspose.Words");
 }
 Merger.create(mergerContext)
         .from(inputDoc1)
         .from(inputDoc2)
         .to(getArtifactsDir() + "LowCode.MergeContextDocuments.3.docx", saveOptions)
         .execute();
 

Parameters:

ParameterTypeDescription
inputjava.lang.StringInput document file name.
loadOptionsLoadOptionsOptional load options used to load the document.

Returns: Processor - Returns processor with specified input file.

to(OutputStream output, SaveOptions saveOptions)

public Processor to(OutputStream output, SaveOptions saveOptions)

Parameters:

ParameterTypeDescription
outputjava.io.OutputStream
saveOptionsSaveOptions

Returns: Processor

to(OutputStream output, int saveFormat)

public Processor to(OutputStream output, int saveFormat)

Parameters:

ParameterTypeDescription
outputjava.io.OutputStream
saveFormatint

Returns: Processor

to(String output)

public Processor to(String output)

Parameters:

ParameterTypeDescription
outputjava.lang.String

Returns: Processor

to(String output, SaveOptions saveOptions)

public Processor to(String output, SaveOptions saveOptions)

Specifies output file for the processor.

Remarks:

If the output consists of multiple files, the specified output file name is used to generate the file name for each part following the rule: ‘outputFile_partIndex.extension’.

Examples:

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


 String doc = getMyDir() + "Big document.docx";

 ConverterContext converterContext = new ConverterContext();

 Converter.create(converterContext)
         .from(doc)
         .to(getArtifactsDir() + "LowCode.ConvertContext.1.pdf")
         .execute();

 Converter.create(converterContext)
         .from(doc)
         .to(getArtifactsDir() + "LowCode.ConvertContext.2.pdf", SaveFormat.RTF)
         .execute();

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
 {
     saveOptions.setPassword("Aspose.Words");
 }
 LoadOptions loadOptions = new LoadOptions();
 {
     loadOptions.setIgnoreOleData(true);
 }
 Converter.create(converterContext)
         .from(doc, loadOptions)
         .to(getArtifactsDir() + "LowCode.ConvertContext.3.docx", saveOptions)
         .execute();

 Converter.create(converterContext)
         .from(doc)
         .to(getArtifactsDir() + "LowCode.ConvertContext.4.png", new ImageSaveOptions(SaveFormat.PNG))
         .execute();
 

Shows how to merge documents into a single output document using context.


 //There is a several ways to merge documents:
 String inputDoc1 = getMyDir() + "Big document.docx";
 String inputDoc2 = getMyDir() + "Tables.docx";

 MergerContext mergerContext = new MergerContext();
 mergerContext.setMergeFormatMode(MergeFormatMode.KEEP_SOURCE_FORMATTING);

 Merger.create(mergerContext)
         .from(inputDoc1)
         .from(inputDoc2)
         .to(getArtifactsDir() + "LowCode.MergeContextDocuments.1.docx")
         .execute();

 LoadOptions firstLoadOptions = new LoadOptions();
 {
     firstLoadOptions.setIgnoreOleData(true);
 }
 LoadOptions secondLoadOptions = new LoadOptions();
 {
     secondLoadOptions.setIgnoreOleData(false);
 }
 Merger.create(mergerContext)
         .from(inputDoc1, firstLoadOptions)
         .from(inputDoc2, secondLoadOptions)
         .to(getArtifactsDir() + "LowCode.MergeContextDocuments.2.docx", SaveFormat.DOCX)
         .execute();

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
 {
     saveOptions.setPassword("Aspose.Words");
 }
 Merger.create(mergerContext)
         .from(inputDoc1)
         .from(inputDoc2)
         .to(getArtifactsDir() + "LowCode.MergeContextDocuments.3.docx", saveOptions)
         .execute();
 

Parameters:

ParameterTypeDescription
outputjava.lang.StringOutput file name.
saveOptionsSaveOptionsOptional save options. If not specified, save format is determined by the file extension.

Returns: Processor - Returns processor with specified output file.

to(String output, int saveFormat)

public Processor to(String output, int saveFormat)

Parameters:

ParameterTypeDescription
outputjava.lang.String
saveFormatint

Returns: Processor

to(ArrayList output, SaveOptions saveOptions)

public Processor to(ArrayList output, SaveOptions saveOptions)

Parameters:

ParameterTypeDescription
outputjava.util.ArrayList
saveOptionsSaveOptions

Returns: Processor

to(ArrayList output, int saveFormat)

public Processor to(ArrayList output, int saveFormat)

Parameters:

ParameterTypeDescription
outputjava.util.ArrayList
saveFormatint

Returns: Processor

toOutput(ArrayList output, SaveOptions saveOptions)

public Processor toOutput(ArrayList output, SaveOptions saveOptions)

Parameters:

ParameterTypeDescription
outputjava.util.ArrayList
saveOptionsSaveOptions

Returns: Processor

toOutput(ArrayList output, int saveFormat)

public Processor toOutput(ArrayList output, int saveFormat)

Parameters:

ParameterTypeDescription
outputjava.util.ArrayList
saveFormatint

Returns: Processor