Use convert to grab a specific page from a PDF file

imagemagickpdf

I know I have done this before, so I'm sure it's possible, I just forget how to do it. There's a way to tell convert to grab a specific page of a PDF, and I'd like to keep the format of that page as PDF.

Best Answer

ImageMagick is a tool for bitmap images, which most PDFs aren't. If you use it, it will rasterize the data, which is often not desirable.

Pdftk can extract one or more pages from a PDF file.

pdftk A=input.pdf cat A42 A43 output pages_42_43.pdf

If you have a LaTeX installation with PDFLaTeX, you can use pdfpages. There's a shell wrapper for pdfpages, pdfjam.

pdfjam -o pages_42_43.pdf input.pdf 42,43

Another possibility (overkill here, but useful for requirements more complex that one page) is Python with the PyPdf library.

#!/usr/bin/env python
import copy, sys
from pyPdf import PdfFileWriter, PdfFileReader
input = PdfFileReader(sys.stdin)
output = PdfFileWriter()
for i in [42, 43]:
    output.addPage(input.getPage(i))
output.write(sys.stdout)
Related Question