PDA

View Full Version : [SOLVED] how to make a new pdf that's a range of pages in another pdf


marko
18th March 2012, 09:44 PM
I have a huge pdf file about my new motherboard, each range of pages is for a different language. That is pages 1-63 is english, 64-## is some other language and so on. I want to filter just those first 1-63 pages into a new pdf so I can just load that pdf for English (makes searching much faster ).

I know the Adobe Acrobat Professional can do that (filter to a new pdf by page range) but is there a free software way to do this? pdfseparate only seems to make a flood of individual pages:

pdfseparate -f 1 -l 63 motherboard.pdf newmotherboard_%d.pdf

and when I even tried that it segfaults. The man page says that it won't work on encrypted pdfs but pdfinfo says it's not an encrypted pdf. Is there some other app that works and can filter one pdf as a page range to another? thanks

Solved: I found you can load the original pdf into adobe reader, then do a print to file (check the "Print to File" checkbox near the bottom of the print dialog) with the selected page range (here 1-63). The printed file to disk is a postscript file, so you can then use
ps2pdf inputfile.ps inputfile.pdf which then converts the ps file to a pdf.

jswmcw
18th March 2012, 10:36 PM
You should be able to print straight to PDF. I do it all the time. In the print dialog, there should be an option to choose .pdf or .ps.

Sent from my Galaxy Nexus using Tapatalk

marko
18th March 2012, 10:41 PM

The print dialog I'm seeing in Adobe reader didn't have the pdf checkbox (I know what you mean, I've seen it before but I'm not seeing it now for some reason). Even if you hit the "Advanced" button I don't see it. The print dialog I'm given by Adobe Reader is shown as the attachment. I'm using the latest Adobe Reader version 9.4.7 that's in the repositories.

Gareth Jones
18th March 2012, 10:49 PM
Try:
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dFirstPage="${first}" \
-dLastPage="${last}" -sOutputFile="${outfile}" "${infile}"
(This is copied from a script I used for extracting thesis chapters for proof reading, so replace the shell variables with the appropriate values.)

marko
19th March 2012, 12:13 AM
That gs command is pretty useful, I made a python script to wrap it so it's easy to use:

USAGE: pdffilter.py 1 20 somefile.pdf

would take the pdf file 'somefile.pdf' then make a new pdf called somefile.pdf.new that only contains pages 1 - 20

#!/usr/bin/python
# pdffilter.py
#

import sys
import subprocess
import os

if len(sys.argv) != 4:
sys.exit("USAGE: {0} {1} {2} {3} ".format(sys.argv[0],
"<starting page number>",
"<end range page number>",
"<input pdf filename>") )
if not os.path.isfile(sys.argv[3]):
sys.exit("No such pdf file {0}".format(sys.argv[3]) )

# user modifiable string to append to the name of the input file to create the name
# of the new file
suffix = 'new'

command = ['gs', '-q', '-dBATCH', '-dNOPAUSE', '-sDEVICE=pdfwrite', "-dFirstPage={0}".format(sys.argv[1]),
"-dLastPage={0}".format(sys.argv[2]), "-sOutputFile={0}.{1}".format(sys.argv[3], suffix), sys.argv[3] ]

# return the call rc to the shell as the return code
sys.exit(subprocess.call(command))