5

I want to exctact pages from a pdf document such that all pages are extracted except the first one and the last one. Code but (end-1) does not work, nor 2-end-1

pdftk 1.pdf cat 2-(end-1) output output.pdf
Léo Léopold Hertz 준영
  • 6,788
  • 29
  • 91
  • 193

3 Answers3

11
pdftk yourpdfile.pdf cat 2-r2 output out.pdf
  • Confirmed! This one works! – Léo Léopold Hertz 준영 Mar 31 '17 at 09:18
  • 3
    Docs: *You can reference page numbers in reverse order by prefix‐ ing 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 doc‐ ument, 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.* – Léo Léopold Hertz 준영 Mar 31 '17 at 09:20
6

You can define a range and remove pages from it (using ~) to achieve this:

pdftk 1.pdf cat 2-end~end output output.pdf

This tells pdftk cat to take the pages from the second page to the last page included (2-end), and remove the last page from the range (~end). The result is a PDF containing everything apart from the first and last pages of the original.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
4

You can use the following format:

pdftk A=1.pdf cat A2-(n-1) output 'outputfile_p2-p(n-1).pdf'

You ca determine n through :pdftk 1.pdf dump_data | grep NumberOfPages

e,g: n=8

pdftk A=1.pdf cat A2-7 output 'outputfile_p2-p7.pdf'
GAD3R
  • 63,407
  • 31
  • 131
  • 192