I want to display dynamic header text for each bookmark pages in word doc

I am generating PDF from word template, I am not able to display dynamic header text for each book pages in word doc.

Hi Satish,


Thanks for your inquiry. We suggest you please read following documentation link about creating header/footer in Word document.
How to Create Headers Footers using DocumentBuilder

Please note that 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.

If Section does not have a HeaderFooter of a specific type or the HeaderFooter has no child nodes, this header/footer is considered linked to the header/footer of the same type of the previous section in Microsoft Word. When HeaderFooter contains at least one Paragraph, it is no longer considered linked to previous in Microsoft Word.

If you still face problem, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

Hi Tahir,


For each bookmark pages, header text need to be different.
for ex : Document with 4 pages with 2 bookmarks

BookMark 1 : navigates to page 1

BookMark 2 : navigates to page 3

In BookMark 1 pages (1-2) header text should be BookMark Text1

In BookMark 2 pages (3-4) header text should be BookMark Text2

When ever i am trying to insert the header text BookMark Text1 and BookMark Text2 are displaying in all page headers.

I tried below option which is not working

foreach (Bookmark bm in doc.Range.Bookmarks)
{
Node currentNode = bm.BookmarkStart;
if (currentNode != null)
{
builder.MoveTo(currentNode);
Section currentSection = builder.CurrentSection;
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.CurrentSection.HeadersFooters.LinkToPrevious(false);
builder.Write(bm.text);
}
}

Hi Satish,


Thanks for your inquiry. Please note that HeaderFooter is a section-level node and can only be a child of Section. A section may have one or multiple pages. In your case, we suggest you please insert the section break at the end of page 2 and insert bookmark text in Primary header of Section.

Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.