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);
builderA.CurrentSection.HeadersFooters.Add(headerPrimaryCurrent);
}
if (headerFirstCurrent == null)
{
headerFirstCurrent = new HeaderFooter(mainDoc, HeaderFooterType.HeaderFirst);
builderA.CurrentSection.HeadersFooters.Add(headerFirstCurrent);
}
if (headerEvenCurrent == null)
{
headerEvenCurrent = new HeaderFooter(mainDoc, HeaderFooterType.HeaderEven);
builderA.CurrentSection.HeadersFooters.Add(headerEvenCurrent);
}
// Add nodes from Branding document header.
foreach (Node node in headerToCopy.ChildNodes)
{
// headerPrimaryCurrent.AppendChild(node.Clone(true));
headerFirstCurrent.AppendChild(node.Clone(true));
// headerEvenCurrent.AppendChild(node.Clone(true));
}
return builderA.Document;
}