Free Support Forum - aspose.com

Can i control the Header display

Hi,

I am creating the header using DocBuilder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

but it will display header in all pages. I have many forms i want that only one forms should have header rest should not have header , can i do that ?

forms are created dynamically.

Thanks.

Hi

Thanks for your request. Try to use the following code.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

//create header

HeaderFooter header = new HeaderFooter(doc, HeaderFooterType.HeaderPrimary);

Paragraph paragraph = new Paragraph(doc);

Run run = new Run(doc);

run.Text = "Header";

paragraph.AppendChild(run);

header.AppendChild(paragraph);

builder.InsertBreak(BreakType.PageBreak);

//insert section break

builder.InsertBreak(BreakType.SectionBreakNewPage);

//add header to current section

builder.CurrentSection.HeadersFooters.Add(header);

builder.InsertBreak(BreakType.PageBreak);

doc.Save(@"257_98196_jonathanh\out.doc");

This code will create document that contains four pages. First and second pages doesn’t have a header and third and forth has a header.

I hope that it will help you.

Best regards.

Thanks it works.