Page instructions

Some tools allow you (or ask you) to specify which pages of a PDF are to be taken into account.

In general, these instructions are to be given in a pages option.

Methods for targeting pages

2 methods allow you to indicate pages:

  • page index: this method allows you to target a single page from its position in the file (more precisely its index, starting from 0)
            
              // Targeting the first and second pages
              options: { pages: [0, 1] }
            
          
    The above instruction is equivalent to the following:
            
              // Targeting the first and second pages
              options: { pages: [{ page: 0 }, { page: 1 }] }
            
          
    This format is used by certain tools to be able to add additional parameters (for example the page duplication tool, to be able to add a number of duplicates, the position where to place the duplicates, etc.)
  • range: this method allows you to target several successive pages by indicating the first and last page
            
              // Targeting pages 1 to 5
              options: { pages: [{ range: [0, 4]}] }
            
          

These 2 methods can be combined to indicate both single pages and ranges of pages.

Shortcuts

Some shortcuts will allow you to calculate page indexes more easily. These shortcuts are even more useful when you do not know in advance the number of pages contained in a PDF.

They can be used for any method (single pages and ranges of pages).

  • first: targets the first page (same as specifying 0)
  • last: targets the last page
  • all: targets all pages
  • calculation: you can combine a shortcut with a calculation using the operator - or / to get the index of a page
            
              options: {
                pages: [
                  'last',   // Last page
                  'last-1'  // Second last page
                  'last/2'  // Middle page
                ],
              }