Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have a set of PDF documents that each have a few extra pages. I'd like to remove the first two and last pages from each of them. Preview only lets me look at and annotate a PDF, not edit one. Can anyone recommend a (free/freeware) tool to do this? I'm using 10.5 PPC so that does limit some of my options. Command line or GUI is fine.


Ok, in Preview it seems I can delete pages by hitting ⌘⌫ on the thumbnails, but it will then not give me the option to save. I can then try printing the altered document to PDF, but I am leery of this because I don't want to loose any metadata (I have to double-check all the files to see how much metadata there is if I decide on this course).


Just tried Acrobat at work, that doesn't work. The files are mod-protected by a password.

share|improve this question
4  
Preview on 10.6 Snow Leopard and 10.7 Lion will let you edit PDFs and save them in this fashion. –  Wheat Williams May 2 '12 at 15:11
2  
Maybe your PDFs are protected, that's why Preview refuses to offer saving the modified files. –  iolsmit May 2 '12 at 15:19
    
Preview in Lion is saving the files automatically, isn't it? –  lhf Jun 28 '12 at 10:58
    
Preview can cut pages in a PDF if allowed. –  Thorbjørn Ravn Andersen Feb 24 '13 at 21:03
add comment

5 Answers

For the command-line I can recommend:

pdftk, the PDF Toolkit (for the Snow-Leopard installer you can try Pacifist to get the binaries or use the older version)

Merge PDF Documents

Split PDF Pages into a New Document

Rotate PDF Pages or Documents

If your PDF is edit-protected, you may want to try qpdf (via e.g. homebrew) to remove the restrictions first.

QPDF is a command-line program that does structural, content-preserving transformations on PDF files. It could have been called something like pdf-to-pdf. It also provides many useful capabilities to developers of PDF-producing software or for people who just want to look at the innards of a PDF file to learn more about how they work.

share|improve this answer
    
It's going to take some work for me to figure out how to build it (127 errors!) –  CyberSkull May 3 '12 at 1:28
    
I couldn't find a binary for qpdf with a quick search - but qpdf is also available via Macports or Fink. Maybe you got better luck trying one of these packet-managers to install/build qpdf –  iolsmit May 3 '12 at 15:48
    
I just found an older version (2.2.2) of qpdf as universal binary here: r.research.att.com/libs –  iolsmit May 3 '12 at 15:51
add comment

PDFpen from Smile Software is a commercial program that can do this and much more. The latest version for Lion is PDFpen 5.8, but you can purchase a copy of their older version 4.7.1, which is compatible with 10.5 Leopard.

share|improve this answer
add comment

Combine PDFs

...is a tool that does this task very fast and simple. It costs $30 in the Mac App Store, but you can still download the completely free version 3.0 on their website.

The free version 3.01 is already several years old, but I've been using it in Lion without problems. Here's how you do your task very simply explained:

enter image description here

1 - note: you'll find also version 4.1 and 4.0 offered as a download, but they are shareware

share|improve this answer
add comment

Preview can selectively export pages of a PDF through the printing options. I just download IRS form W9, which has four pages. The first page is the form that needs to be filled out, and the final three pages are instructions. I filled out the first page using Preview on Mountain Lion, then I chose to print. From the print screen, I chose to include only one page (the first page), and saved to PDF with the button at the bottom of the print sheet. This technique can be used for individual pages or a range of pages.

share|improve this answer
add comment

The commandline for pdftk (suggested by iolsmit) to remove the first 2 and the last two pages from a 30-page PDF named input1.pdf is this:

pdftk \
  input1.pdf \
  cat 3-28 \
  output input1_p3-28.pdf

The very latest, still unreleased version of Ghostscript (which will become v. 9.06 in a few weeks) can also do it:

gs \
  -o input1_p3-28.pdf \
  -dFirstPage=3 \
  -dLastPage=28 \
  -sDEVICE=pdfwrite \
   input1.pdf

To automatically determine the number of pages, you could use pdfinfo (also available from MacPorts):

pdfinfo input1.pdf

will show the collection of embedded metadata about the PDF. Hence you could script the whole process of removing the pages. First, put the number of pages into a variable:

_endpage=$(( $(pdfinfo input1.pdf | grep Pages: | awk '{print $2}' sed 's# ##g') - 2 ))

Then, run one of the above commandlines using this variable:

pdftk input1.pdf cat 3-${_endpage} output input1_p3-${_endpage}.pdf

Just put these two lines into a Bash script called remove-my-4-pages.sh:

#!/bin/bash
_endpage=$(( $(pdfinfo ${1}.pdf | grep Pages: | awk '{print $2}' sed 's# ##g') - 2 ))
pdftk ${1}.pdf cat 3-${_endpage} output ${2}.pdf

and run it like this:

bash  remove-my-4-pages.pdf  myinput.pdf  myoutput.pdf

Just make sure that the pdfinfo and pdftk utilities are in your $PATH environment variable. Otherwise the script will not run. If you installed these utilities from MacPorts, you can put the followng line into your ~/.bash_profile:

export PATH=/opt/local/bin:$PATH
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.