Extract even-numbered and odd-numbered pages of a PDF into two separate PDFs
Solution 1
I'd do it with pdftk.
pdftk A=all.pdf cat Aodd output odd.pdf
pdftk A=all.pdf cat Aeven output even.pdf
Solution 2
pdftk is not Open Source any longer, unfortunately. (That is a long story.)
Plain gs engine can do it, though:
gs -sDEVICE=pdfwrite \
-sPageList=odd \
-sOutputFile=odd.pdf \
-dBATCH -dNOPAUSE \
file.pdf
Then substitute 'odd' with 'even' to select even pages.
Solution 3
With poppler-utils
tools you could first extract single pages with pdfseparate
:
pdfseparate infile.pdf piece-%d.pdf
into pieces like piece-1.pdf
, piece-2.pdf
... piece-n.pdf
where n
is the total number of pages in your original pdf.
You could then join them with pdfunite
(and a shell that supports using an increment value with range expansion: {<START>..<END>..<INCR>}
):
pdfunite piece-{1..n..2}.pdf odd.pdf
pdfunite piece-{2..n..2}.pdf even.pdf
Finally, remove the pieces:
rm piece-{1..n}.pdf
Solution 4
You can do it with pdftocairo
from Poppler:
pdftocairo -pdf -e input.pdf output.pdf
for odd pages, and:
pdftocairo -pdf -o input.pdf output.pdf
for even pages.
!! Keep in mind only that currently (pdftocairo v. 0.80.0) there is a bug: https://gitlab.freedesktop.org/poppler/poppler/issues/873 and odd and even pages options are mixed up. ))
Related videos on Youtube
Matthew
Updated on September 18, 2022Comments
-
Matthew over 1 year
I have a PDF that consists of several hundred pages of bilingual text. Since I need to use OCR on each language separately, I want to grab the even and odd pages and make two separate PDFs, using
convert
orghostscript
. The language I want to do first is on the odd-numbered pages. Whatconvert
orghostscript
command can I use to grab these and write them to a new file?-
Gilles 'SO- stop being evil' almost 13 yearsIs there a reason why you want to use ImageMagick or Ghostscript, as opposed to more appropriate tools?
-
Matthew almost 13 years@Gilles nope. pdftk works for me. thanks...
-
-
don_crissti about 2 yearsThis answer deserves more upvotes.