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

Free Support Forum - aspose.com

HeaderFoother for more sections

Hi, I want to create a document (. docx,. doc) that will have a header and footer on the the first page different than on the other pages. This I managed to do, but when I set a header and footer on the the other pages (not on the first) blank, display the same header as the first page. Where am I doing wrong?

Hi

Thanks for your request. I think, in this case you can use first page header. Please see the following code:

// Create a blank document.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

// Specify that we want headers and footers different for first and other pages.

builder.PageSetup.DifferentFirstPageHeaderFooter = true;

// Create the headers.

builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);

builder.Write("Header First");

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

builder.Write("Header Primary");

// Create pages in the document.

builder.MoveToDocumentStart();

builder.Writeln("Page1");

builder.InsertBreak(BreakType.SectionBreakNewPage);

builder.PageSetup.DifferentFirstPageHeaderFooter = false;

builder.Writeln("Page2");

builder.InsertBreak(BreakType.PageBreak);

builder.Writeln("Page3");

builder.InsertBreak(BreakType.SectionBreakNewPage);

builder.Writeln("Page4");

builder.InsertBreak(BreakType.PageBreak);

builder.Writeln("Page5");

doc.Save("C:\\Temp\\out.doc");

Hope this helps.

Best regards,

OK thanks… this help me very well.