Merger

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

public class Merger extends Processor

Represents a group of methods intended to merge a variety of different types of documents into a single output document.

Remarks:

The specified input and output files or streams, along with the desired merge and save options, are used to merge the given input documents into a single output document.

The merging functionality supports over 35 different file formats.

Examples:

Shows how to merge documents into a single output document.


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

 Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.1.docx", new String[]{inputDoc1, inputDoc2});

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
 {
     saveOptions.setPassword("Aspose.Words");
 }
 Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.2.docx", new String[]{inputDoc1, inputDoc2}, saveOptions, MergeFormatMode.KEEP_SOURCE_FORMATTING);

 Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.3.pdf", new String[]{inputDoc1, inputDoc2}, SaveFormat.PDF, MergeFormatMode.KEEP_SOURCE_LAYOUT);

 LoadOptions firstLoadOptions = new LoadOptions();
 {
     firstLoadOptions.setIgnoreOleData(true);
 }
 LoadOptions secondLoadOptions = new LoadOptions();
 {
     secondLoadOptions.setIgnoreOleData(false);
 }
 Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.4.docx", new String[]{inputDoc1, inputDoc2}, new LoadOptions[]{firstLoadOptions, secondLoadOptions},
         saveOptions, MergeFormatMode.KEEP_SOURCE_FORMATTING);

 Document doc = Merger.merge(new String[]{inputDoc1, inputDoc2}, MergeFormatMode.MERGE_FORMATTING);
 doc.save(getArtifactsDir() + "LowCode.MergeDocument.5.docx");

 doc = Merger.merge(new String[]{inputDoc1, inputDoc2}, new LoadOptions[]{firstLoadOptions, secondLoadOptions}, MergeFormatMode.MERGE_FORMATTING);
 doc.save(getArtifactsDir() + "LowCode.MergeDocument.6.docx");
 

Methods

MethodDescription
create()Creates new instance of the mail merger processor.
create(MergerContext context)Creates new instance of the mail merger 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.
merge(Document[] inputDocuments, int mergeFormatMode)
merge(InputStream[] inputStreams, LoadOptions[] loadOptions, int mergeFormatMode)
merge(InputStream[] inputStreams, int mergeFormatMode)
merge(OutputStream outputStream, InputStream[] inputStreams, LoadOptions[] loadOptions, SaveOptions saveOptions, int mergeFormatMode)
merge(OutputStream outputStream, InputStream[] inputStreams, SaveOptions saveOptions, int mergeFormatMode)
merge(OutputStream outputStream, InputStream[] inputStreams, int saveFormat)
merge(String outputFile, String[] inputFiles)Merges the given input documents into a single output document using specified input and output file names using MergeFormatMode.KEEP_SOURCE_FORMATTING.
merge(String outputFile, String[] inputFiles, LoadOptions[] loadOptions, SaveOptions saveOptions, int mergeFormatMode)
merge(String outputFile, String[] inputFiles, SaveOptions saveOptions, int mergeFormatMode)
merge(String outputFile, String[] inputFiles, int saveFormat, int mergeFormatMode)
merge(String[] inputFiles, LoadOptions[] loadOptions, int mergeFormatMode)
merge(String[] inputFiles, int mergeFormatMode)
mergeToImages(InputStream[] inputStreams, ImageSaveOptions saveOptions, int mergeFormatMode)
mergeToImages(String[] inputFiles, ImageSaveOptions saveOptions, int mergeFormatMode)
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)

create()

public static Merger create()

Creates new instance of the mail merger processor.

Returns: Merger

create(MergerContext context)

public static Merger create(MergerContext context)

Creates new instance of the mail merger processor.

Examples:

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

Parameters:

ParameterTypeDescription
contextMergerContext

Returns: Merger

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.

merge(Document[] inputDocuments, int mergeFormatMode)

public static Document merge(Document[] inputDocuments, int mergeFormatMode)

Parameters:

ParameterTypeDescription
inputDocumentsDocument[]
mergeFormatModeint

Returns: Document

merge(InputStream[] inputStreams, LoadOptions[] loadOptions, int mergeFormatMode)

public static Document merge(InputStream[] inputStreams, LoadOptions[] loadOptions, int mergeFormatMode)

Parameters:

ParameterTypeDescription
inputStreamsjava.io.InputStream[]
loadOptionsLoadOptions[]
mergeFormatModeint

Returns: Document

merge(InputStream[] inputStreams, int mergeFormatMode)

public static Document merge(InputStream[] inputStreams, int mergeFormatMode)

Parameters:

ParameterTypeDescription
inputStreamsjava.io.InputStream[]
mergeFormatModeint

Returns: Document

merge(OutputStream outputStream, InputStream[] inputStreams, LoadOptions[] loadOptions, SaveOptions saveOptions, int mergeFormatMode)

public static void merge(OutputStream outputStream, InputStream[] inputStreams, LoadOptions[] loadOptions, SaveOptions saveOptions, int mergeFormatMode)

Parameters:

ParameterTypeDescription
outputStreamjava.io.OutputStream
inputStreamsjava.io.InputStream[]
loadOptionsLoadOptions[]
saveOptionsSaveOptions
mergeFormatModeint

merge(OutputStream outputStream, InputStream[] inputStreams, SaveOptions saveOptions, int mergeFormatMode)

public static void merge(OutputStream outputStream, InputStream[] inputStreams, SaveOptions saveOptions, int mergeFormatMode)

Parameters:

ParameterTypeDescription
outputStreamjava.io.OutputStream
inputStreamsjava.io.InputStream[]
saveOptionsSaveOptions
mergeFormatModeint

merge(OutputStream outputStream, InputStream[] inputStreams, int saveFormat)

public static void merge(OutputStream outputStream, InputStream[] inputStreams, int saveFormat)

Parameters:

ParameterTypeDescription
outputStreamjava.io.OutputStream
inputStreamsjava.io.InputStream[]
saveFormatint

merge(String outputFile, String[] inputFiles)

public static void merge(String outputFile, String[] inputFiles)

Merges the given input documents into a single output document using specified input and output file names using MergeFormatMode.KEEP_SOURCE_FORMATTING.

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 merge documents into a single output document.


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

 Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.1.docx", new String[]{inputDoc1, inputDoc2});

 OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
 {
     saveOptions.setPassword("Aspose.Words");
 }
 Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.2.docx", new String[]{inputDoc1, inputDoc2}, saveOptions, MergeFormatMode.KEEP_SOURCE_FORMATTING);

 Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.3.pdf", new String[]{inputDoc1, inputDoc2}, SaveFormat.PDF, MergeFormatMode.KEEP_SOURCE_LAYOUT);

 LoadOptions firstLoadOptions = new LoadOptions();
 {
     firstLoadOptions.setIgnoreOleData(true);
 }
 LoadOptions secondLoadOptions = new LoadOptions();
 {
     secondLoadOptions.setIgnoreOleData(false);
 }
 Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.4.docx", new String[]{inputDoc1, inputDoc2}, new LoadOptions[]{firstLoadOptions, secondLoadOptions},
         saveOptions, MergeFormatMode.KEEP_SOURCE_FORMATTING);

 Document doc = Merger.merge(new String[]{inputDoc1, inputDoc2}, MergeFormatMode.MERGE_FORMATTING);
 doc.save(getArtifactsDir() + "LowCode.MergeDocument.5.docx");

 doc = Merger.merge(new String[]{inputDoc1, inputDoc2}, new LoadOptions[]{firstLoadOptions, secondLoadOptions}, MergeFormatMode.MERGE_FORMATTING);
 doc.save(getArtifactsDir() + "LowCode.MergeDocument.6.docx");
 

Parameters:

ParameterTypeDescription
outputFilejava.lang.StringThe output file name.
inputFilesjava.lang.String[]The input file names.

merge(String outputFile, String[] inputFiles, LoadOptions[] loadOptions, SaveOptions saveOptions, int mergeFormatMode)

public static void merge(String outputFile, String[] inputFiles, LoadOptions[] loadOptions, SaveOptions saveOptions, int mergeFormatMode)

Parameters:

ParameterTypeDescription
outputFilejava.lang.String
inputFilesjava.lang.String[]
loadOptionsLoadOptions[]
saveOptionsSaveOptions
mergeFormatModeint

merge(String outputFile, String[] inputFiles, SaveOptions saveOptions, int mergeFormatMode)

public static void merge(String outputFile, String[] inputFiles, SaveOptions saveOptions, int mergeFormatMode)

Parameters:

ParameterTypeDescription
outputFilejava.lang.String
inputFilesjava.lang.String[]
saveOptionsSaveOptions
mergeFormatModeint

merge(String outputFile, String[] inputFiles, int saveFormat, int mergeFormatMode)

public static void merge(String outputFile, String[] inputFiles, int saveFormat, int mergeFormatMode)

Parameters:

ParameterTypeDescription
outputFilejava.lang.String
inputFilesjava.lang.String[]
saveFormatint
mergeFormatModeint

merge(String[] inputFiles, LoadOptions[] loadOptions, int mergeFormatMode)

public static Document merge(String[] inputFiles, LoadOptions[] loadOptions, int mergeFormatMode)

Parameters:

ParameterTypeDescription
inputFilesjava.lang.String[]
loadOptionsLoadOptions[]
mergeFormatModeint

Returns: Document

merge(String[] inputFiles, int mergeFormatMode)

public static Document merge(String[] inputFiles, int mergeFormatMode)

Parameters:

ParameterTypeDescription
inputFilesjava.lang.String[]
mergeFormatModeint

Returns: Document

mergeToImages(InputStream[] inputStreams, ImageSaveOptions saveOptions, int mergeFormatMode)

public static InputStream[] mergeToImages(InputStream[] inputStreams, ImageSaveOptions saveOptions, int mergeFormatMode)

Parameters:

ParameterTypeDescription
inputStreamsjava.io.InputStream[]
saveOptionsImageSaveOptions
mergeFormatModeint

Returns: java.io.InputStream[]

mergeToImages(String[] inputFiles, ImageSaveOptions saveOptions, int mergeFormatMode)

public static InputStream[] mergeToImages(String[] inputFiles, ImageSaveOptions saveOptions, int mergeFormatMode)

Parameters:

ParameterTypeDescription
inputFilesjava.lang.String[]
saveOptionsImageSaveOptions
mergeFormatModeint

Returns: java.io.InputStream[]

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