projectz

Tech, Gadgets, Photography, Social Media and Poor Spelling

Extracting pages from a pdf file using linux command line

This is one of those useful command line tricks which a sysadmin needs in the brains toolbox.

pdftk is a tool which we can use to split or extract pages from a pdf document.


To install pdfktk on debian based systems

sudo apt-get install pdftk
Let us say we have a pdf file,temp.pdf, with 100 pages in it. We want to extranct the pages 20 to 30 and create a new pdf . We can do it using pdftk

pdftk temp.pdf cat 20-30 output new.pdf 

If the command returns to the prompt with no errors, we will have a new pdf file in the same directory with the name new.pdf.

We can pick specific pages instead of a range by just passing the page numbers.

To create a new pdf by extracting pages 21,25, and 28 we can use.

pdftk temp.pdf cat 21 25 28 output new.pdf
We can also select only even/odd pages by passing the option even/odd respectively

To extract all the odd numbered pages we can use the range as 1-end and use the keyword odd.

pdftk temp.pdf cat 1-endodd

Source: http://tuxthink.blogspot.co.uk/

Leave a comment

Information

This entry was posted on October 8, 2012 by in guides, Linux, Ubuntu and tagged , , , , , , , .