Adding page numbering in footer
Create a document with page numbering in the footer. Used in multi-page documents such as reports, contracts, and instructions. Allows readers to easily navigate the document structure:
- create footer for all document pages (Api, ApiSection/GetFooter);
- add text field with automatic page numbering (ApiDocumentContent/AddElement, Api/CreateParagraph);
- configure center alignment for better visual perception (ApiParagraph/SetJc);
- set standard neutral font with 10-11 pt size (ApiRun/SetFontSize, ApiRun/SetFontFamily);
- automatic value updates when exporting or saving document (ApiDocument/CreateNumbering).
- Code
- Result
let doc = Api.GetDocument();
// Add content to the first page
let paragraph1 = Api.CreateParagraph();
paragraph1.AddText("First page of the document");
doc.Push(paragraph1);
// Add page break
let paragraph2 = Api.CreateParagraph();
paragraph2.AddPageBreak();
doc.Push(paragraph2);
// Add content to the second page
let paragraph3 = Api.CreateParagraph();
paragraph3.AddText("Second page of the document");
doc.Push(paragraph3);
// Create footer
let section = doc.GetFinalSection();
let footer = section.GetFooter("default", true);
let footerParagraph = footer.GetElement(0);
footerParagraph.SetJc("center");
footerParagraph.SetFontFamily("Arial");
footerParagraph.SetFontSize(22); // 11pt in half-points
// Add page number field
footerParagraph.AddText("Page ");
footerParagraph.AddPageNumber();
footerParagraph.AddText(" of ");
footerParagraph.AddPagesCount();