We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

AppendDocument Method not Honoring Margins

Tech Support,

I am currently using the Aspose Document object to Append Documents together for a consolidation of different word documents before sending them to the printer. Everything was working great, until I realized that it wasn’t honoring margins of the appended documents. This is a huge issue to us since the appended document which is 1 page prints out as two pages because everything gets shifted down in the document. I have used both arguments in AppendDocument but get the same results.


I’m hoping that there is a property for the Document Class that I just need to set to honor the margins and not adjust them, but I’m worried there isn’t.

Please let me know if there is anything I can do on my side to help you guys come to a resolution.



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.

'Initialization in Load Function
Me.oAsposeDocument = New Aspose.Words.Document(strFileToLoad)
Me.oMasterAsposeDocument = New Aspose.Words.Document()

'After Apose Document has replaced Tokens in file
Me.oMasterAsposeDocument.AppendDocument(me.oAsposeDocument, ImportFormatMode.KeepSourceFormatting)

'Load New Document
Me.oAsposeDocument = Nothing
Me.oAsposeDocument = New Aspose.Words.Document(strFileToLoad)

***Repeats the 2nd, 3rd step until it’s complete.***

'Prints Master Document when Completed
Dim pd As New System.Drawing.Printing.PrinterSettings
pd.PrinterName = Printer
pd.Copies = CopiesToPrint

I am not using a DocumentBuilder object to achieve this. Maybe this might fix our issue?

If I need to send you example documents, so that you can see how stuff is being shifted down, please let me know. I’m guessing you could recreate the issue, by expanding the margins on the document to be appended.


Thanks for your request. Please attach your input and output document here for testing? We will check the issue and provide you more information.

Best regards,

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…

oAsposeDocument = New Aspose.Words.Document(strFileToLoad)

and only messes up when you use the AppendDocument function to append it to another document.


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.

master.AppendDocument(doc1, ImportFormatMode.KeepSourceFormatting);

master.AppendDocument(doc2, ImportFormatMode.KeepSourceFormatting);

// Save master document.


The output document looks exactly the same as source documents.

Best regards,

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.

- Ryan

<<I sent this to you in your personal email, but will paste it here for history purposes.>>

Hi Alexey,

I’m currently trying to resolve an issue with the AppendDocument function. I think I might have a solution to resolving my issue, but I am unsure how to approach it via code or via a property. In the current file attached, I was able remove page 3 by removing the section break on page 1 and replacing it with a page break(ctrl+enter (Office 2010)) instead.

To recreate my example:

1. Open Word Document page1and4.doc
2. Turn on Paragraph Marks on Home Tab
3. Find Section Break on Page 1
4. Remove it. (Page 2 should come up onto page 1.
5. Put cursor before the loan number (01-001-000134) that was on top of page two and ctrl-enter.
6. You will now see Page Break there.

Page 3 should now be page 2

What is the best way to replace the Section Breaks with Page Breaks via code? Is this the correct approach to our solution of this issue?


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)


if (string.IsNullOrEmpty(headersFooter.GetText().Trim()))

headersFooter.FirstParagraph.ParagraphBreakFont.Size = 1;


doc1.AppendDocument(doc2, ImportFormatMode.KeepSourceFormatting);


Hope this could help you.

Best regards,

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.

Here is the code that was applied.

If Not Me.oAsposeMasterDocument.FirstSection Is Nothing Then
For Each headersfooters As HeaderFooter In Me.oAsposeMasterDocument.FirstSection.HeadersFooters
If String.IsNullOrEmpty(headersfooters.GetText.Trim()) Then
headersfooters.FirstParagraph.ParagraphBreakFont.Size = 1
End If
End If

Me.oAsposeMasterDocument.AppendDocument(oAsposeDocument, ImportFormatMode.KeepSourceFormatting)
Me.oAsposeDocument = Nothing

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.

Another issue I am noticing is renumbering of page numbers in the footers. Is there any way to turn that off?

Hi Ryan,

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:


Best regards,