This message was posted using Page2Forum from Document.AppendDocument Method - Aspose.Words for .NET
Let me clarify a little more to help with trying to fix the issue. The code being used is pretty simple.
Thanks for your request. Please attach your input and output document here for testing? We will check the issue and provide you more information.
Here is the consolidated document and individual document at the end. You can use the individual document and append it on any document to get the same result. As you can see in the consolidated document, the 2nd to last page and the last page should be 1 page, not two. This works ok, if you initialize the document object with the document like so…
Thank you for additional information. But unfortunately, I cannot reproduce the problem on my side. I used the latest version of Aspose.Words and the following code for testing:
// Create a master document.
Document master = new Document();
// Open source document.
Document doc1 = new Document(@"Test001\transmittal.doc");
Document doc2 = new Document(@"Test001\Consolidated.doc");
// Append source documents to the master document.
// Save master document.
The output document looks exactly the same as source documents.
Ok, I set up a better testing scenerio. Page 1 and 4 print fine on 1 page when using the document object, but when appending page 1 and page 4, page 4 goes to two pages.
<<I sent this to you in your personal email, but will paste it here for history purposes.>>
Thank you for additional information. In your documents, the firs document has an empty header, but the second does not. If there are no headers/footers in section, it will inherit headers/footers from the previous section.
You can disable inheriting using LinkToPreviouse method:
However, this method creates headers/footers automatically, If any of the headers or footers do not exist. This is needed to prevent inheriting from the previous section.
As a workaround, you can try setting font of the paragraph in the newly created headers/footers to very small values, this must decrease influence to the document’s layout:
Document doc1 = new Document(@"Test001\page1.doc");
Document doc2 = new Document(@"Test001\page4.doc");
foreach (HeaderFooter headersFooter in doc2.FirstSection.HeadersFooters)
headersFooter.FirstParagraph.ParagraphBreakFont.Size = 1;
Hope this could help you.
So I applied the code above, and it did shift the 2nd page up, but it still adds a final blank page as the third page. Did you guys get the same results??? I also tried this against a big set of documents only to get the same result as before. One of the things I did try was replacing section breaks with page breaks. This didn’t work though as it converted my portrait pages to landscape.
With the document I had sent you above in the attachment, I was able to make it fall down to 2 pages when removing the section break and replacing it with a page break. As I had said before though, this is not a complete solution though, since when applying this logic to the whole master document, it sets the master document to all landscape pages when the master document has mixed landscape/portrait settings.
Thank you for additional information. Yes, I also observed that an empty page appears at the end of the generated document. Unfortunately, I do not have any other solution for you.
Regarding page numbers, I think the following article could be useful for you: