Free Support Forum - aspose.com

Leave out Header and Footer in appended Document

Hi,

my original document has Headers and Footer and i want to append a document, which does not have headers and footers. The appended document should stay header and foot free, while the original document has headers and footers. Is that possible? Here is how i append:

public void AppendDocument(Document document)
{
            Document attachedDocument = new Document(@"C:\attachment.docx");

            // Set the appended document to start on a new page. 
            attachedDocument.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
            // Append the source document using the original styles found in the source document. 
            document.AppendDocument(attachedDocument, ImportFormatMode.KeepSourceFormatting);
}

Thanks and best regards,

Peter

@peter.mueller,

Thanks for your inquiry. Please use HeadersFooters.LinkToPrevious method as shown below to get the desired output. This method links or unlinks the specified header or footer to the corresponding header or footer in the previous section.

Document doc = new Document(MyDir + "doc1.docx");
Document attachedDocument = new Document(MyDir + @"doc2.docx");

// Set the appended document to start on a new page. 
attachedDocument.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
attachedDocument.FirstSection.HeadersFooters.LinkToPrevious(false);
// Append the source document using the original styles found in the source document. 
doc.AppendDocument(attachedDocument, ImportFormatMode.KeepSourceFormatting);

doc.Save(MyDir + "18.5.docx");

@tahir.manzoor,

thanks for the quick reply/support!

@peter.mueller,

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.