Skip to main content

Custom header and footer generation

Applies predefined headers and footers to all pages in the document.

(function () {
let doc = Api.GetDocument();
let sections = doc.GetSections();

for (let section of sections) {
// Remove existing headers and footers
section.RemoveHeader("default");
section.RemoveFooter("default");

// Create new header and footer
let header = section.GetHeader("default", true);
let footer = section.GetFooter("default", true);

// Set header content
let headerPara = header.GetElement(0);
headerPara.AddText("Your Header Text");
headerPara.SetJc("center");

// Set footer content
let footerPara = footer.GetElement(0);
footerPara.AddText("Your Footer Text - Page ");
footerPara.AddPageNumber();
footerPara.SetJc("center");
}

return true;
})();

Methods used: GetDocument, GetSections, RemoveHeader, RemoveFooter, GetHeader, GetFooter, GetElement, AddText, SetJc, AddPageNumber

Result

CustomHeaderFooterGenerationCustomHeaderFooterGeneration