Header and Footer
Header and Footer refer to annotations added at the top and bottom of a document, typically containing information such as titles, page numbers, and brand identification. By including headers and footers in a document, it becomes easier to navigate and identify, thereby enhancing the document's readability and professionalism.
In a PDF document, only one header and footer can exist, and adding a new header and footer will overwrite the old header and footer.
Add Header and Footer
The steps to add headers and footers are as follows:
Retrieve the header and footer objects within the document.
Specify the pages where headers and footers should be added.
Set attributes such as color and font size for the headers and footers.
Update the headers and footers on the pages.
This example shows how to add header and footer:
CPDFDocument document = CPDFDocument.InitWithFilePath("File Path");
CPDFHeaderFooter headerFooter = document.GetHeaderFooter();
headerFooter.SetPages("1-3");
headerFooter.SetText(0, @"<<1,2>> page");
byte[] color = { 255, 0, 0 };
headerFooter.SetTextColor(0, color);
headerFooter.SetFontSize(0, 14);
headerFooter.Update();
2
3
4
5
6
7
8
Header and Footer Regular Expression Explanation
Headers and footers support format-specific regular expressions that take effect when headerFooter.setRules(1)
is set, in the format: <<\d+,\d+>>|<<\d+>>|<\d+,>>
- <<i>> :
i
is the starting value of the page number. - <<i,f>>:
i
is the starting value of the page number, andf
is the number of digits in the page number, if the actual page number is not enough, it will be automatically filled with 0 in front.
eg: When text is set to "<<1,2>> page", the text displayed on the first page is "01 page".
Remove Header and Footer
Steps to Remove headers and footers:
Retrieve the header and footer objects from the document.
Remove the headers and footers.
This example shows how to remove the header and footer:
CPDFHeaderFooter headerFooter = document.GetHeaderFooter();
headerFooter.Clear();
2