Free Support Forum - aspose.com

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);

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;
}

Hi

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

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.pagesetup.differentfirstpageheaderfooter.html

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

Hope this helps.

Best regards,

Thanks that did it