1.5 KiB
1.5 KiB
title | description | type | page_title | slug | position | tags | res_type |
---|---|---|---|---|---|---|---|
Insert Field in Header | Learn how you can insert a field in the header of a document using WordsProcessing. | how-to | Insert Field in Header | insert_field_in_header | 0 | header, field | kb |
Product Version | Product | Author |
---|---|---|
2020.3.1019 | RadWordsProcessing | Dimitar Karamfilov |
Description
You need to add a field in the header for example to display page numbering.
Solution
This can be achieved by adding a paragraph to the header and then moving the editor position to this paragraph. Once this is done you can insert the field and move the position to another paragraph in the document.
C# Insert page numbering in he header
{{region insert_field_in_header}}
RadFlowDocument document = new RadFlowDocument();
var section = document.Sections.AddSection();
var header = section.Headers.Add();
Paragraph paragraph = header.Blocks.AddParagraph();
paragraph.TextAlignment = Alignment.Right;
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
editor.MoveToParagraphStart(paragraph);
editor.InsertText("Page ");
editor.InsertField("PAGE", "3");
editor.InsertText(" of ");
editor.InsertField("NUMPAGES", "5");
var paragrpah2 = section.Blocks.AddParagraph();
editor.MoveToParagraphStart(paragrpah2);
document.UpdateFields();
{{endregion}}