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

Free Support Forum - aspose.com

How to move a document builder cursor to the end of a header?

Hi, I need a bit of help. It’s probably really easy but I can’t find any examples showing it.

I need to add text to an existing page header.
This moves me to the start:
DocBuilder1.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
And this inserts text at the top of the header:
DocBuilder1.Writeln(“Extra text added to the header”);
But I need the text to be added after the text that is already there.
How do I move to the end of the header so I can insert text there?

Thanks
Karin

@KarinMX

You can use the following code example to achieve your requirements. Hope this helps you.

If you still face problem, please ZIP and attach your input and expected output documents here for our reference. We will then provide you more information about your query.

Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.MoveToParagraph(builder.CurrentStory.Paragraphs.IndexOf(builder.CurrentStory.LastParagraph), -1);
builder.Write("...HeaderPrimary...");

doc.Save(MyDir + "output.docx");

That’s it!
The bit I hadn’t found out about was builder.CurrentStory.Paragraphs.I couldn’t work out how to go “one level up”.

Problem solved.

Thank you.

Karin