Headers and Footers ​
Foxit PDF SDK for Web supports adding, reading, updating, and removing headers and footers in PDF documents. Common APIs include:
PDFDoc.addHeaderFooter()PDFDoc.getHeaderFooter()PDFDoc.updateHeaderFooter()PDFDoc.removeHeaderFooter()
Headers and footers are written into PDF content and are suitable for page numbers, document IDs, dates, or fixed notices. Export the document after changes to save results.
Add Headers and Footers ​
PDFDoc.addHeaderFooter(headerFooter) adds headers and footers.
javascript
await pdfDoc.addHeaderFooter({
pageRange: [[0, pdfDoc.getPageCount() - 1]],
header: {
center: {
text: 'Foxit PDF SDK Web'
}
},
footer: {
right: {
text: 'Page <PageNumber>'
}
}
});Read Headers and Footers ​
javascript
const headerFooter = await pdfDoc.getHeaderFooter();Use the result to check whether the document already has headers and footers, or as baseline data for updates.
Update Headers and Footers ​
PDFDoc.updateHeaderFooter(headerFooter) updates existing headers and footers.
javascript
const headerFooter = await pdfDoc.getHeaderFooter();
await pdfDoc.updateHeaderFooter({
...headerFooter,
footer: {
center: {
text: 'Confidential'
}
}
});Remove Headers and Footers ​
javascript
await pdfDoc.removeHeaderFooter();Save Changes ​
After adding, updating, or removing headers and footers, export the document to save results.
javascript
const file = await pdfDoc.getFile({
fileName: 'header-footer.pdf'
});Notes ​
- Headers and footers modify PDF content; confirm with users before applying changes they may need to save.
- Page indexes start at
0. - If the document already contains headers and footers, call
getHeaderFooter()before updating to read the current configuration.