Free Support Forum - aspose.com

Possible to modify an existing header?

How can I modify an existing HeaderFooter?

It appears that this line: builder.moveToHeaderFooter(HeaderFooterType.HeaderFirst);

replaces the existing header with a new one.

Thanks


To get a hold of the header/footer safely and reliably you can use the following code:

HeaderFooter headerFirst = section.HeadersFooters[HeaderFooterType.HeaderFirst];

if (headerFirst == null)

{

headerFirst = new HeaderFooter(section.Document, HeaderFooterType.HeaderFirst);

section.HeadersFooters.Add(headerFirst);

}

This code gets a hold of the existing header or creates a new header if the header of the specified type does not exist in this section.

Please mind that there are total six types of headers/footers and every section in the document can have each own set of headers/footers. Section can automatically display the header/footer defined in the previous section if you set the header/footer IsLinkedToPrevious setting to true.

Best regards,

Thanks for the above. I’ve run into another issue that I’ll post in a new thread