We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

First and Even Page Header and Footer Ignored

Hi

I am using Aspose Words 14.11, with Visual Studio 2010, and .NET 4.0.
I have discovered a problem with the headers and footers when generating a Word document. If you specify text for HeaderFirst, HeaderEven, FooterFirst, or FooterEven, that text does not appear in the finished document. Weirdly, if you put in some distinct text and search for it from within Word itself, you get search results, even though they don’t go anywhere when you click on them.
Here is some sample code (C#):

	Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Header
builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
builder.Write(“Header First”);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);
builder.Write(“Header Even”);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.Write(“Header Primary”);
// Footer
builder.MoveToHeaderFooter(HeaderFooterType.FooterFirst);
builder.Write(“Footer First”);
builder.MoveToHeaderFooter(HeaderFooterType.FooterEven);
builder.Write(“Footer Even”);
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.Write(“Footer Primary”);
// Write a bunch of lines to pad the document out to 4 or 5 pages
builder.MoveToSection(doc.IndexOf(builder.CurrentSection));
for (int i = 1; i <= 200; i++)
{
builder.Writeln(string.Format(“Document padding line #{0}.”, i));
}

If you save the resulting document, only the primary header and footer will appear.
Could you have a look into this, and let me know what I’m doing wrong?

Thanks
Chris Fairall.

I’ve figured it out.

For those who are also experiencing this problem, you need to set the DifferentFirstPageHeaderFooter and OddAndEvenPagesHeaderFooter properties of the PageSetup property of the section:

	builder.CurrentSection.PageSetup.DifferentFirstPageHeaderFooter = true;
	builder.CurrentSection.PageSetup.OddAndEvenPagesHeaderFooter = true;
That did the trick.

Thanks
Chris Fairall.

Hi Chris,


Thanks for your inquiry. Yes, you need to set DifferentFirstPageHeaderFooter and OddAndEvenPagesHeaderFooter properties oto true. It’s great you were able to find what you were looking for. Please let us know any time you have any further queries.

Best regards,