com.aspose.words
Class Merger

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

public abstract class Merger 
extends java.lang.Object

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

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.

Example:

Shows how to merge documents into a single output document.
//There is a several ways to merge documents:
Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SimpleMerge.docx", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" });

OoxmlSaveOptions ooxmlSaveOptions = new OoxmlSaveOptions();
ooxmlSaveOptions.setPassword("Aspose.Words");
Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SaveOptions.docx", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, ooxmlSaveOptions, MergeFormatMode.KEEP_SOURCE_FORMATTING);

Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SaveFormat.pdf", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, SaveFormat.PDF, MergeFormatMode.KEEP_SOURCE_LAYOUT);

Document doc = Merger.merge(new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, MergeFormatMode.MERGE_FORMATTING);
doc.save(getArtifactsDir() + "LowCode.MergeDocument.DocumentInstance.docx");

Method Summary
static Documentmerge(Document[] inputDocuments, int mergeFormatMode)
           Merges the given input documents into a single document and returns Document instance of the final document.
static voidmerge(java.lang.String outputFile, java.lang.String[] inputFiles)
           Merges the given input documents into a single output document using specified input and output file names.
static voidmerge(java.lang.String outputFile, java.lang.String[] inputFiles, SaveOptions saveOptions, int mergeFormatMode)
           Merges the given input documents into a single output document using specified input output file names and save options.
static voidmerge(java.lang.String outputFile, java.lang.String[] inputFiles, int saveFormat, int mergeFormatMode)
           Merges the given input documents into a single output document using specified input output file names and the final document format.
static Documentmerge(java.lang.String[] inputFiles, int mergeFormatMode)
           Merges the given input documents into a single document and returns Document instance of the final document.
 

Method Detail

merge

public static Document merge(Document[] inputDocuments, int mergeFormatMode)
                          throws java.lang.Exception
Merges the given input documents into a single document and returns Document instance of the final document.
Parameters:
inputDocuments - The input documents.
mergeFormatMode - A MergeFormatMode value. Specifies how to merge formatting that clashes.

Example:

Shows how to merge input documents to a single document instance.
DocumentBuilder firstDoc = new DocumentBuilder();
firstDoc.getFont().setSize(16.0);
firstDoc.getFont().setColor(Color.BLUE);
firstDoc.write("Hello first word!");

DocumentBuilder secondDoc = new DocumentBuilder();
secondDoc.write("Hello second word!");

Document mergedDoc = Merger.merge(new Document[] { firstDoc.getDocument(), secondDoc.getDocument() }, MergeFormatMode.KEEP_SOURCE_LAYOUT);
Assert.assertEquals("Hello first word!\fHello second word!\f", mergedDoc.getText());

merge

public static void merge(java.lang.String outputFile, java.lang.String[] inputFiles)
                      throws java.lang.Exception
Merges the given input documents into a single output document using specified input and output file names.

By default MergeFormatMode.KEEP_SOURCE_FORMATTING is used.

Parameters:
outputFile - The output file name.
inputFiles - The input file names.

Example:

Shows how to merge documents into a single output document.
//There is a several ways to merge documents:
Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SimpleMerge.docx", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" });

OoxmlSaveOptions ooxmlSaveOptions = new OoxmlSaveOptions();
ooxmlSaveOptions.setPassword("Aspose.Words");
Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SaveOptions.docx", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, ooxmlSaveOptions, MergeFormatMode.KEEP_SOURCE_FORMATTING);

Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SaveFormat.pdf", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, SaveFormat.PDF, MergeFormatMode.KEEP_SOURCE_LAYOUT);

Document doc = Merger.merge(new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, MergeFormatMode.MERGE_FORMATTING);
doc.save(getArtifactsDir() + "LowCode.MergeDocument.DocumentInstance.docx");

merge

public static void merge(java.lang.String outputFile, java.lang.String[] inputFiles, SaveOptions saveOptions, int mergeFormatMode)
                      throws java.lang.Exception
Merges the given input documents into a single output document using specified input output file names and save options.
Parameters:
outputFile - The output file name.
inputFiles - The input file names.
saveOptions - The save options.
mergeFormatMode - A MergeFormatMode value. Specifies how to merge formatting that clashes.

Example:

Shows how to merge documents into a single output document.
//There is a several ways to merge documents:
Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SimpleMerge.docx", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" });

OoxmlSaveOptions ooxmlSaveOptions = new OoxmlSaveOptions();
ooxmlSaveOptions.setPassword("Aspose.Words");
Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SaveOptions.docx", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, ooxmlSaveOptions, MergeFormatMode.KEEP_SOURCE_FORMATTING);

Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SaveFormat.pdf", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, SaveFormat.PDF, MergeFormatMode.KEEP_SOURCE_LAYOUT);

Document doc = Merger.merge(new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, MergeFormatMode.MERGE_FORMATTING);
doc.save(getArtifactsDir() + "LowCode.MergeDocument.DocumentInstance.docx");

merge

public static void merge(java.lang.String outputFile, java.lang.String[] inputFiles, int saveFormat, int mergeFormatMode)
                      throws java.lang.Exception
Merges the given input documents into a single output document using specified input output file names and the final document format.
Parameters:
outputFile - The output file name.
inputFiles - The input file names.
saveFormat - A SaveFormat value. The save format.
mergeFormatMode - A MergeFormatMode value. Specifies how to merge formatting that clashes.

Example:

Shows how to merge documents into a single output document.
//There is a several ways to merge documents:
Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SimpleMerge.docx", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" });

OoxmlSaveOptions ooxmlSaveOptions = new OoxmlSaveOptions();
ooxmlSaveOptions.setPassword("Aspose.Words");
Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SaveOptions.docx", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, ooxmlSaveOptions, MergeFormatMode.KEEP_SOURCE_FORMATTING);

Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SaveFormat.pdf", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, SaveFormat.PDF, MergeFormatMode.KEEP_SOURCE_LAYOUT);

Document doc = Merger.merge(new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, MergeFormatMode.MERGE_FORMATTING);
doc.save(getArtifactsDir() + "LowCode.MergeDocument.DocumentInstance.docx");

merge

public static Document merge(java.lang.String[] inputFiles, int mergeFormatMode)
                          throws java.lang.Exception
Merges the given input documents into a single document and returns Document instance of the final document.
Parameters:
inputFiles - The input file names.
mergeFormatMode - A MergeFormatMode value. Specifies how to merge formatting that clashes.

Example:

Shows how to merge documents into a single output document.
//There is a several ways to merge documents:
Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SimpleMerge.docx", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" });

OoxmlSaveOptions ooxmlSaveOptions = new OoxmlSaveOptions();
ooxmlSaveOptions.setPassword("Aspose.Words");
Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SaveOptions.docx", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, ooxmlSaveOptions, MergeFormatMode.KEEP_SOURCE_FORMATTING);

Merger.merge(getArtifactsDir() + "LowCode.MergeDocument.SaveFormat.pdf", new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, SaveFormat.PDF, MergeFormatMode.KEEP_SOURCE_LAYOUT);

Document doc = Merger.merge(new String[] { getMyDir() + "Big document.docx", getMyDir() + "Tables.docx" }, MergeFormatMode.MERGE_FORMATTING);
doc.save(getArtifactsDir() + "LowCode.MergeDocument.DocumentInstance.docx");

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