Delete PDF pages

The removal tool allows you to delete one or more pages from a PDF. Find out how to use it very simply in this guide.

Basic page deletion

In order to use the page deletion tool, add a task in your pipeline that targets the delete-pages tool.

The options parameter allows you to specify which pages you want to delete from the PDF, based on their indexes.

    
      // Creating the form data for the pipeline
      const form = new FormData();

      form.append(
        'tasks',
        [
          {
            tool: 'delete-pages',
            // Delete the first and second pages
            options: { pages: [0, 1] },
          },
        ],
      );
    
  

Range deletion

The API allows you to remove a range of pages, rather than listing all indexes one-by-one.

    
      // Delete the first 5 pages
      options: { pages: [{ range: [0, 4] }] }
    
  

Multiple removal instructions

You can define several removal instructions.

The instructions are executed in the order given in the pages parameter. It is therefore important to know that for instruction n, the indices must be calculated taking into account instruction n-1.

    
      options: {
        pages: [
          // Delete the first page
          0,
          // Delete the 3 last pages
          { range: ['last-3', 'last'] },
        ],
      },