Skip to main content

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:

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();