How to insert "Continued" text in the header of document after first page using .NET

Hi Team,

We needed a functionality where we can have a Header along with “Continued” keyword to the content which gets continued to the next page. Currently we are using “Section” for every different topic which is to be printed on the word doc. Do we have any option to do so?

I am using Aspose word 18.9

I am attaching the sample of what I needed.

Let me know if its doable.Sample for continued functionality.zip (11.8 KB)

@ashish29190

Following code example shows how to insert text into header of document. HeaderFooter is a section-level node and can only be a child of Section. There can only be one HeaderFooter or each HeaderFooterType in a Section. You can insert your desired content into header of document. Hope this helps you.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Specify that we want headers and footers different for first, even and odd pages
builder.PageSetup.DifferentFirstPageHeaderFooter = true;
builder.PageSetup.OddAndEvenPagesHeaderFooter = true;

// Create the headers
builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
builder.Write("Header for the first page");
builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);
builder.Write("Header for even pages");
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.Write("Header for all other pages");

// Create three pages in the document
builder.MoveToSection(0);
builder.Writeln("Page1");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page2");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page3");

doc.Save(MyDir + "DocumentBuilder.HeadersAndFooters.docx");

Hi @tahir.manzoor, Thanks for quick reply. I don’t have any problem creating headers and footers. I have implemented different Headers and Footers for every section in the document. The problem is, How could I know the number of pages a particular content is going to take. I have content that is HTML string. For e.g. if there is one section, then its content will be HTML string which can be of single page or 2 pages or any number of pages. In this case how can I modify the Header from the second page of that content for adding Page title along wit ‘Continued’ word.

Regards,
Ashish M

@ashish29190

In your case, we suggest you please insert the text “Continued” in Header Primary and set the PageSetup.DifferentFirstPageHeaderFooter property to true. Hope this helps you.

Thanks @tahir.manzoor. Will try this and let you know.

@ashish29190

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

@tahir.manzoor I tried your solution and yes it worked perfectly.

Solution :
1.Set PageSetup.DifferentFirstPageHeaderFooter = true
2.Attach content for Header.First (First page of current section)
3.Attach different content for Header.Primary (remaining pages of current section)

Iterate 2 & 3 steps for multiple sections if any.

Thanks for help @tahir.manzoor !!

@ashish29190

Thanks for your feedback. It is nice to hear from you that your problem has been solved.