Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove the last page of a pdf file using PDFtk?

Tags:

linux

pdf

pdftk

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

like image 422
user1974753 Avatar asked Jul 17 '13 17:07

user1974753


People also ask

How can I delete a PDF page online?

First select the PDF document from which you want to delete pages. After Acrobat uploads the file, sign in. Then highlight the page thumbnails you want to delete and click the dustbin icon in the top toolbar to delete the selected pages.


Video Answer


2 Answers

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/

like image 142
This isn't my real name Avatar answered Sep 23 '22 06:09

This isn't my real name


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 
like image 40
johnwhitington Avatar answered Sep 19 '22 06:09

johnwhitington