Problem merging documents in a specific order

I am using v14.10.0.0

I need to combine a series of documents, and overall that works fine. My problem is that one document (document A) has a small top and bottom margin. When I combine it with document B, depending on the order, I have a problem.

If I put document A as the first document and document B as the second, the final document looks fine. If I have B first and then merge in document A, the first page of document A gets partially pushed onto a second page.

Can anyone point me in the right direction? The following is the method I am using to combine the documents.

public void LocalCombineDocuments(Aspose.Words.Document dstDoc, Aspose.Words.Document srcDoc)
{
    srcDoc.FirstSection.PageSetup.SectionStart = Aspose.Words.SectionStart.NewPage;
    srcDoc.FirstSection.HeadersFooters.LinkToPrevious(false);
    foreach (Aspose.Words.HeaderFooter headersFooter in srcDoc.FirstSection.HeadersFooters)
    {
        if (string.IsNullOrEmpty(headersFooter.GetText().Trim()))
        {
            headersFooter.FirstParagraph.ParagraphBreakFont.Size = 1;
        }
    }
    dstDoc.AppendDocument(srcDoc, Aspose.Words.ImportFormatMode.KeepSourceFormatting);
}

Also, if you want sample files, can I send them somewhere to an email? They are more sensitive company documents. Thanks!

Hi Brad,

Thanks for your inquiry. We need your sample documents and simple console application with source code to reproduce the problem on our end. Please note that it is safe to attach files in the forum. If you attach your documents here, only you and Aspose staff members can download them. Also you can zip these resources and send the zip file to my e-mail as described here:
https://forum.aspose.com/t/aspose-words-faq/2711

Best regards,

Email with sample program and sample word files has been sent.

Hi Brad,

Thanks for your inquiry. The problem occurs because of footers in ‘__sampleLoan.doc’ document. You can fix it by using the following code:

Document tilaDoc = new Document(MyDir + @"__sampleTila.doc");
Document loanDoc = new Document(MyDir + @"__sampleLoan.doc");
foreach (Section sec in loanDoc.Sections)
sec.ClearHeadersFooters(); 
Document uberDoc = loanDoc;
uberDoc.AppendDocument(tilaDoc, ImportFormatMode.KeepSourceFormatting);
uberDoc.Save(MyDir + @"out.doc");

Best regards,

We have loan docs that have things like page numbers in the footers and can’t just be wiped. Is there something specific that is causing it that I might change.

I assume the ClearHeadersAndFooters wipes out everything, right?

Hi Brad,

Thanks for your inquiry. We are working over your query and will get back to you soon.

Best regards,

Is there any update on this one?

Hi Brad,

Thanks for being patient. Please spare us some time for the investigation of this issue, we’ll get back to you today or tomorrow.

Best regards,

Hi Brad,

Thanks for being patient. We tested the scenario and have managed to reproduce the same problem. For the sake of correction, we have logged this problem in our issue tracking system WORDSNET-11173. Our development team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Hi Brad,

Thanks for being patient. The problem occurs because MS Word reserves some space for header regardless of actual header size. You can set header distance as follows to fix this issue:

public static void LocalCombineDocuments(Aspose.Words.Document dstDoc, Aspose.Words.Document srcDoc)
{
    srcDoc.FirstSection.PageSetup.HeaderDistance = 0;
    srcDoc.FirstSection.PageSetup.SectionStart = Aspose.Words.SectionStart.NewPage;
    srcDoc.FirstSection.HeadersFooters.LinkToPrevious(false);
    foreach (Aspose.Words.HeaderFooter headersFooter in srcDoc.FirstSection.HeadersFooters)
    {
        if (string.IsNullOrEmpty(headersFooter.GetText().Trim()))
        {
            headersFooter.FirstParagraph.ParagraphBreakFont.Size = 1;
        }
    }
    dstDoc.AppendDocument(srcDoc, Aspose.Words.ImportFormatMode.KeepSourceFormatting); //.UseDestinationStyles might one day need KeepSourceFormatting
}

I hope, this helps.

Best regards,

Hi Brad,

Regarding WORDSNET-11173, our development team has completed the work on your issue and has come to a conclusion that this issue and the undesired behaviour you’re observing is actually not a bug in Aspose.Words. So, we have closed this issue as ‘Not a Bug’. Please use the workaround from my previous post.

Best regards,