I am finding it hard to phrase this question and could not find an online solution for what I'm trying to do.
I know how to split a large PDF into single pages with PDFTK using the following script:
pdftk your_file.pdf burst output your_directory/page_%02d.pdf
But now I want to split the PDF by every other page, so that each new PDF has TWO (2) pages (e.g. pages 1 + 2 together, pages 3 + 4 together, 5 + 6, etc.).
I know that Acrobat does this like a champ, however I need something I can execute from Powershell.
I am open to alternatives/workarounds, like taking the single pages and combining them by two's after single bursting.
You can use
sejda-console
, it's open source under AGPLv3 and can be downloaded from the project GitHub page.You can use the
splitbyevery
command whichIn you case the command line will be something like:
sejda-console splitbyevery -n 2 -f /tmp/input_file.pdf -o /out_dir
You can use the cat keyword to generate files from the desired pages.
A bash script can be added in order to be easier to use:
I found Szakacs Peter's solution to be wonderful, but the bash script needed three tweaks: starting
$COUNTER
at 1 so that it refers to the first page of the pdf; adding double braces on line four so that(($COUNTER+1))
evaluates; another$COUNTER
to make the output file names unique.The final bash script that solved this for me was:
Then just save this as something like
burst2page.sh
, do achmod u+x burst2page.sh
to make it executable, then run it with./burst2page.sh
This PowerShell script will
Change the first two vars to fit your environment.
Edited to work with variable sets of pages and to properly handle the overhang.
Edited again: found a much easier way do shorten the last set of pages.
Sample output
Brad Smith's script is good however it won't work in that shape. When you don't define $NUMBEROFPAGES, the script throws you an error
script.sh: line 3: [: 1: unary operator expected
. I suggest to change it to: