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

Free Support Forum - aspose.com

First and Even Page Header and Footer Ignored


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.Write(“Header First”);
builder.Write(“Header Even”);
builder.Write(“Header Primary”);
// Footer
builder.Write(“Footer First”);
builder.Write(“Footer Even”);
builder.Write(“Footer Primary”);
// Write a bunch of lines to pad the document out to 4 or 5 pages
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?

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.

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,