Merge multiple documents in single document without change formatting of single documents

Requirement: Merge multiple documents in single document without change formatting of single documents.

Issue: Formatting of documents and page number changed after merge done.

Sample Code: https://online.exportcentral.com.au/AsposeSampleApp.zip

Explanation: We have 4 already generated document using Aspose word.

  1. 20161213183218089.docx (Attach image 1.png)

  2. 20161213183229150.docx (Attach image 2.png)

  3. 20161213183229700.docx (Attach image 3.png)

  4. 20161213183230620.docx (Attach image 4.png)

So total number of pages : 6 and all have different formatting

After merge using code (Attach image 5.png)Output:

(Attach image 6.png)
(Attach image 7.png)

Any update on this

Hi Manish,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same page number issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-14610. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

Could you please share some more detail about formatting issue? We will investigate the issue on our side and provide you more information.

For formatting issue : 20161223164706613.Docx (An example of 3 merge documents)

here is single documents of all three

  1. 20161223165255243.docx
  2. 20161223165404271.docx
  3. 20161223165436234.docx

please check suggest

Hi Manish,

Thanks for sharing the document. We suggest you please read about difference between ImportFormat modes from following link.

Differences between ImportFormat Modes

We suggest you please use ImportFormatMode.KeepSourceFormatting mode in Document.AppendDocument method to get the desired output. Hope this helps you.

If you still face problem, please share the screenshot of problematic section of output document along with expected output document. We will then provide you more information about your query.

Thanks for your kind help.Formatting issue resolved 90% by using ImportFormatMode.KeepSourceFormatting.

is there any update on WORDSNET-14610.

Hi Manish,

Thanks for your inquiry. We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. Our developers work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

Currently, your issue is pending for analysis and is in the queue. Once our product team completes the analysis of your issue, we will then be able to provide you an estimate.

Thanks for your patience and understanding.

Hi Manish,

Thanks for your patience. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-14610) as ‘Not a Bug’.

Documents with two pages (20161213183229700.docx and 20161213183230620.docx) have tables which end at the bottom margin. In addition, body of the document has paragraph which located after the table and this paragraph is placed on the next page. Paragraph has size 1 point and is not shown in MS Word, but it causes empty pages in the end of these documents. So these documents have last blank page until content is not added to the end.

Please use option ImportFormatMode.KeepSourceFormatting to preserve formatting from source documents. Also page breaks have to be added to the last paragraph of the 20161213183229700.docx and 20161213183230620.docx to get the desired output. Please use the following code example.

ArrayList ArrFilesSequence = new ArrayList();
ArrFilesSequence.Insert(0, "20161213183218089.docx");
ArrFilesSequence.Insert(1, "20161213183229150.docx");
ArrFilesSequence.Insert(2, "20161213183229700.docx");
ArrFilesSequence.Insert(3, "20161213183230620.docx");
string SoursePath = MyDir;
Document doc = new Document();
// We should call this method to clear this document of any existing content.
doc.RemoveAllChildren();
for (int i = 0; i < ArrFilesSequence.Count; i++)
{
    // Open the document to join.
    Document srcDoc = new Document(Path.Combine(SoursePath, ArrFilesSequence[i].ToString()));
    srcDoc.FirstSection.HeadersFooters.LinkToPrevious(false);
    // Append page breaks for last two documents.
    if (i > 1)
    {
        Run pageBreakRun = new Run(srcDoc, ControlChar.PageBreak);
        srcDoc.FirstSection.Body.LastParagraph.AppendChild(pageBreakRun);
    }
    // Append the source document at the end of the destination document.
    doc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
}
doc.Save(MyDir + "Out v17.1.0.docx");