Remove the last page of a pdf file using PDFtk?

Can someone please tell me how to remove the last page of a PDF file, using PDFtk?


Solution 1:

This will create the outfile.pdf with all but the last page in infile.pdf

pdftk infile.pdf cat 1-r2 output outfile.pdf

Explanation of parameters

  • infile.pdf is the original pdf file
  • cat is the operation
  • 1-r2 is the page range
    • You can reference page numbers in reverse order by prefixing them with the letter r. For example, page r1 is the last page of the document, r2 is the next-to-last page of the document, and rend is the first page of the document. You can use this prefix in ranges, too, for example r3-r1 is the last three pages of a PDF.

  • output will output it to a specific file
  • output.pdf is the output pdf file

More examples are here: https://www.pdflabs.com/docs/pdftk-cli-examples/

Solution 2:

With cpdf, you can reference a page by how far it is from the end of the document, using a tilde, as well as the beginning.

So, we can do

cpdf in.pdf 1-~2 -o out.pdf