Log in Sign up

Add Page Numbers Guide
Learn to develop your own solution to automatically number PDF pages by integrating with iLovePDF’s REST API.

Remember that in order to use our Tool Guides, you need to have previous knowledge about the basics to processing a PDF with our REST API. We strongly recommend that you read the Processing a PDF guide before starting this one.

Basic page numbers

You can add page numbers to your PDF files as shown in this code:

Basic page numbers

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

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.


Default: true

Set starting number

Set starting number

starting_number will let you set from which number the page numbering will start and it is recommended to combine this with first_cover and pages to set which pages will be numbered.


Default: 1

Pages to 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

Default: all

Set numbers font format

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

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.


Default: N

Vertical position of numbers

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.


Default: bottom

Vertical position adjustment of numbers

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!


Default: 0

Horizontal position of numbers

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.


Default: center

Horizontal position adjustment of numbers

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!


Default: 0

Add number to facing pages

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:


Default: false