Add Page Numbers Guide
Learn to develop your own solution to automatically number PDF pages by integrating with iLovePDF’s REST API.
Basic page numbers
You can add page numbers to your PDF files as shown in this code:
By using a page number task as a process tool you will add numbers to your PDF pages.
Many settings can be customized with the advanced options explained in next sections.
Advanced page numbers
Do not number first page
first_cover is a useful property for books or magazines and allows you to avoid numbering the first page of your document. It is recommended to combine this property with first_cover to set from which number you want to begin your PDF page numbers.
Set starting number
Pages to number
pages has plenty of options to be numbered. See them:
- all Means that all pages will be stamped with the watermark. This is the default value
- 3-end Means that pages from third to the last will be stamped
- 1-3,4-9 Means that pages 1 and 3 and in range of 4 to 9, will be stamped with the watermark
- -2-end Means that 2 pages less since the last will be stamped with the watermark
- 3-234 Means that the range of 3 to 234 pages will be stamped with the watermark
Set numbers font format
font_family, font_size and font_color are properties to customize the page numbers font format. The font_family property changes which font will be used, font_size changes the font size, and font_color changes the color of the numbers.
Default: Arial Unicode MS 14px #000000
Format of page number
It is possible to set the page number format and add strings to it concatenated with variables using text. In the code example, the page number content is: "Page N of P" where N is the number of the current page and P is the total number of pages in the PDF document.
Vertical position of numbers
vertical_position allows you to set the vertical position of page numbers to the top or the bottom of the page. Note that there will not be a margin. In order to do this, use vertical_position_adjustment.
Vertical position adjustment of numbers
vertical_position_adjustment applies a displacement of pixels from the standard vertical position. This value can be positive or negative. So watch out, because if you place the number at the bottom of the page with vertical_position and then apply a huge pixel displacement, the page number will be off the page!
Horizontal position of numbers
horizontal_position allows you to set the horizontal position of page numbers to the left, center or right of the page. Take note that left and right positions will be affected by setting facing_pages as you will see in its description.
Horizontal position adjustment of numbers
horizontal_position_adjustment will displace the amount of pixels set in params, from its defined horizontal position. This value can be positive or negative so be careful- If you have your number placed to the right with horizontal_position and horizontal_position_adjustment set to a large positive value, you will place your number outside of the page!
Add number to facing pages
With the facing_pages property you can set your PDF numbering in facing mode, like a book or a magazine. This only takes effect when combined with horizontal_position left or right and will place all page numbers mirrored between pages where left will place numbers to the inside and right to the outside of the page. See the example below for a better understanding: