Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RickyB

macrumors regular
Original poster
Oct 28, 2007
210
6
Hi,

I'd lie to create a service in MacOS which uses automator to split a PDF into halves. For example if I had a 10 page PDF, part 1 would be 1-5 and Part B would be pages 6-10.

I can create a script that easily splits to PDF into single pages, but can't seem to work out how to do what I an asking.

Hope you can help.

Thanks,

Richard
 

Slartibart

macrumors 68030
Aug 19, 2020
2,914
2,628
one option is to do this via a shell script you include in your Automator action.
Because a pdf can have an odd number of total pages I suggest to use pdfinfo from the XPDF command line tools (depending on your system it might be recommmended to install it via brew; or you install from the binary archive from its web site) to get the number of pages in a pdf (for illustration purposes I suggest to put that in a variable x).
With that info you can calculate the page number limits for both “halves” of the pdf (e.g. x - x/2)
Last you can use e.g. Ghostscript to split the file accordingly - you find a nice solution IMHO here.

Other solutions are involving Adobe Acrobat, the Print-dialogue, QPDF, PDFtk… whatever floats your boat 😀


EDIT: provided the PDF has a ToC it would be much more elegant IMHO to use that for splitting, but again YMMV 🤓
 
Last edited:

RickyB

macrumors regular
Original poster
Oct 28, 2007
210
6
one option is to do this via a shell script you include in your Automator action.
Because a pdf can have an odd number of total pages I suggest to use pdfinfo from the XPDF command line tools (depending on your system it might be recommmended to install it via brew; or you install from the binary archive from its web site) to get the number of pages in a pdf (for illustration purposes I suggest to put that in a variable x).
With that info you can calculate the page number limits for both “halves” of the pdf (e.g. x - x/2)
Last you can use e.g. Ghostscript to split the file accordingly - you find a nice solution IMHO here.

Other solutions are involving Adobe Acrobat, the Print-dialogue, QPDF, PDFtk… whatever floats your boat 😀


EDIT: provided the PDF has a ToC it would be much more elegant IMHO to use that for splitting, but again YMMV 🤓
Thanks @Slartibart I'll have a look at that.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.