Free Support Forum -

Adding the header from one document to the first page of another document

I am trying to add a header to only the HeaderFooterType.HeaderFirst of the document, but it does not show up. If I place it in the HeaderFooterType.HeaderPrimary it will show up on every page. My code is below

public static Document AddcustomHeaderToReport(Document mainDoc, Document footerOrHeader)
DocumentBuilder builderA = new DocumentBuilder(mainDoc);
// Copy Header

HeaderFooter headerToCopy = (HeaderFooter)mainDoc.ImportNode(footerOrHeader.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary], true, ImportFormatMode.UseDestinationStyles);

// Get the Current Primary Header

HeaderFooter headerPrimaryCurrent = builderA.CurrentSection.HeadersFooters[HeaderFooterType.HeaderPrimary];

HeaderFooter headerFirstCurrent = builderA.CurrentSection.HeadersFooters[HeaderFooterType.HeaderFirst];

HeaderFooter headerEvenCurrent = builderA.CurrentSection.HeadersFooters[HeaderFooterType.HeaderEven];

// Create header if it does not exist.

if (headerPrimaryCurrent == null)

headerPrimaryCurrent = new HeaderFooter(mainDoc, HeaderFooterType.HeaderPrimary);



if (headerFirstCurrent == null)

headerFirstCurrent = new HeaderFooter(mainDoc, HeaderFooterType.HeaderFirst);



if (headerEvenCurrent == null)

headerEvenCurrent = new HeaderFooter(mainDoc, HeaderFooterType.HeaderEven);



// Add nodes from Branding document header.

foreach (Node node in headerToCopy.ChildNodes)
// headerPrimaryCurrent.AppendChild(node.Clone(true));


// headerEvenCurrent.AppendChild(node.Clone(true));


return builderA.Document;


Thanks for your request. I think, you should simply set this property:

If it is false, the primary header is displayed on the first page.

Hope this helps.

Best regards,

Thanks that did it