We produce word documents and want to merge them and finally save it as PDF. There is always a “main” document where we define header and footer and page number. Then we attach other documents to the main document. These other documents (attachments) should always start on odd pages in the new document.
Example 1) This works
- Main document with 4 pages
- Second document with 2 pages with is going to be attached to the main document
- The result should be a merged document with 6 pages (4 pages from main document followed by 2 pages from the second document including header and footer and page number from main document)
Example 2) Empty page is added, but no header and footer and page number
- Main document with 3 pages
- Second document with 2 pages with is going to be attached to the main document
- The result should be a merged document with 6 pages (3 pages from main document followed by a blank page with header and footer and page number from the main document followed by 2 pages from the attached document with header and footer and page number from the main document)
Tried to achieve my goal by following code:
var mainDocument = new Document(@"c:\temp\MainDocument.docx");
var documentToAttach = new Document(@"c:\temp\Attachment.docx");
// ensure header and footer and page number is applied
documentToAttach.FirstSection.HeadersFooters.LinkToPrevious(true);
// ensure we continue on odd pages
documentToAttach.FirstSection.PageSetup.SectionStart = SectionStart.OddPage;
mainDocument.AppendDocument(anhang, ImportFormatMode.KeepDifferentStyles);
mainDocument.Save(@"c:\temp\Aspose_Merged_Document.pdf", SaveFormat.Pdf);
Problem: Empty page (see Example 2) does not have header and footer and pager numer. How can I solve that?
Example2.zip (52.7 KB)