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

Free Support Forum - aspose.com

Merging documents causes headers to copy

My solution takes several documents produced through aspose at different times and merge's them all together into a single file before sending it off. The code I've attached works great as long as all documents have a header. If I merge in a document that doesn't have any header information initialy though it brings in the header to this document from the document I'm merging to (either that or the next document I merge in with header info adds it to my already merged document, not exactly sure which). The header information in question if it matters is an image added to the header using the watermark sample code. Is there a wrong setting I'm using to say that each document section should retain it's own header and footer?

document.FirstSection.PageSetup.SectionStart = SectionStart.NewPage

For Each srcSection As Section In document

srcSection.PageSetup.PageWidth = mergeDocument.LastSection.PageSetup.PageWidth

srcSection.PageSetup.PageHeight = mergeDocument.LastSection.PageSetup.PageHeight

Dim newSection As Section = DirectCast(mergeDocument.ImportNode(srcSection, True, ImportFormatMode.KeepSourceFormatting), Section)

mergeDocument.Sections.Add(newSection)

Next

Hi Eric,

Thanks for your inquiry.

To avoid this situation the headers and footers must be unlinked by calling the HeaderFooterCollection.LinkToPrevious method on the first section of the source document. Passing false to this method will unlink all types of headers and footers from the previous section. It is enough to unlink only the first section as any further linked sections in the source document now will not inherit any headers or footers from the previous section. For more details, please visit the following link:

I hope, this helps.

Best regards,