7

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.

4
  • 5
    Preview on 10.6 Snow Leopard and 10.7 Lion will let you edit PDFs and save them in this fashion.
    – user9290
    Commented May 2, 2012 at 15:11
  • 2
    Maybe your PDFs are protected, that's why Preview refuses to offer saving the modified files.
    – iolsmit
    Commented May 2, 2012 at 15:19
  • Preview in Lion is saving the files automatically, isn't it?
    – lhf
    Commented Jun 28, 2012 at 10:58
  • Preview can cut pages in a PDF if allowed. Commented Feb 24, 2013 at 21:03

6 Answers 6

5

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.

1
  • +1 Selective Export and Merge works like a breeze with Preview
    – frhd
    Commented Sep 15, 2015 at 13:39
4

As I have written before, QPDF is great. Use it this way to extract pages 3-998 from 1000 pages of input.pdf and save it as output.pdf.

qpdf --pages input.pdf 3-998 -- input.pdf output.pdf

Please note that input.pdf is written twice.

You can install as described here:

Download MacPorts and invoke:

sudo port install qpdf

Or you can install it with Homebrew:

brew install qpdf

It is a great tool for PDF manipulation, which is very fast, has very few dependencies. "It can encrypt and linearize files, expose the internals of a PDF file, and do many other operations useful to end users and PDF developers."

http://sourceforge.net/projects/qpdf/

It can work with password protected files. For example:

qpdf --empty --copy-encryption=encrypted.pdf --encryption-file-password=pass
--pages encrypted.pdf --password=pass 1 ./encrypted.pdf --password=pass 1 --
outfile.pdf
4

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.

3
  • It's going to take some work for me to figure out how to build it (127 errors!)
    – CyberSkull
    Commented May 3, 2012 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
    Commented May 3, 2012 at 15:48
  • I just found an older version (2.2.2) of qpdf as universal binary here: r.research.att.com/libs
    – iolsmit
    Commented May 3, 2012 at 15:51
1

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.

1

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
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .