Printing a booklet on a Mac

I had a 47-page PDF document that I wanted to turn into a compact A5 booklet – you know, one of those things where you get out the big stapler and make something like this:

Unfortunately, you need to print page 39 on the same page as page 10, and then pages 40 and 9 on the other side, etc, and when you get to anything more than about 4 pages it’s hard and tedious to do this by hand and get it right. My HP printer driver had a ‘booklet’ facility, and it worked OK for 8 pages, but let me down when given any more.

Now, there are utilities you can buy which can do exactly this, but why would I spend a tenner or two when I could instead use a few otherwise lucrative working hours and build one myself?

So here’s my solution, which could be a lot tidier, but does the only tricky bit of the job: getting the pages in the right order. It’s an Automator script which you can run as a service: once installed, you can right-click on a PDF and select Services, and you should find a ‘Make Booklet PDF’ option. It produces a new PDF on your Desktop with appropriately shuffled pages. You can then just print that using Preview as follows:

  • Go into the Layout section of the Print dialog.
  • Select Two-Sided Printing
  • Set Pages per Sheet to ‘2’
  • Set the ‘Two-Sided’ option to ‘Short-Edge Binding’

Now, please note: You should understand how this works before trying it! It’s not complex, and I could have made it much prettier and self-explanatory, but I was using Automator, which is so far from a real programming language as to be frustrating. It does, however, have a few useful ways of manipulating PDFs without having to install anything else, and my script will at least prompt you with some of the following information when you run it.

(Note too that if you’re reading this in 2022 or later, you definitely want to continue on to read the updates at the bottom of the post!)

OK,

  • First, the number of pages in your starting PDF must be a multiple of 4. Fortunately, you can easily append blank pages in Preview if needed. Select the last page and choose ‘Edit > Insert > Blank Page’ as often as needed and then save. The script will warn you if your page count isn’t right.

  • Then when you run the script, it will create a folder called ‘booklet-pages’ on your desktop. In here, it will create one PDF for each page of your document.

  • Finally, it will work out what order these pages should be in, and create a new ‘booklet.pdf’ on your desktop with the pages reassembled in that order.

  • You can then delete the ‘booklet-pages’ folder.

So, here’s a zip file containing the Automator script. You should be able to double-click it and open it in Automator if you want to see what’s inside, but I think if you put it into your ~/Library/Services folder within your home directory, it will probably just appear as a service if you right-click on a PDF file in the Finder.

Make Booklet PDF on desktop.zip (for pre-Monterey Macs)

Hope it’s useful to someone! Sorry I can’t provide any support if you try it, but recommendations and improvements are welcome from anybody with more Automator stamina than me! All I can say is that it works nicely on my Mac running High Sierra (10.13.6).

Some updates: please read these when you’ve read all of the above

Update:

If you’re doing this kind of thing, you may also like a video of MacOS PDF tips and tricks, which I made back in 2016 but which people still say they find useful.

Update April 2022:

MacOS version 12.3 and onwards doesn’t include Python 2, on which this script depended, and, while it does include Python 3, Apple haven’t updated Automator to make the switch quite as trivial as it should be! However, I’ve created an updated version which works on my Mac; I hope somebody can confirm that it works for them too! (See below.)

Update June 2022

The new version of the ZIP file below tries harder to find a copy of Python 3 on your computer.

For MacOS 12.3 and later:

  • Download this ZIP file: Make booklet PDF on desktop – 2022b.zip.
  • Your browser may uncompress this for you; if not, then double-click on the ZIP file to reveal the ‘Make booklet PDF on desktop’ workflow inside.
  • Double-click on this and you should be asked if you want to install it as a ‘Quick action’
  • This will then be copied into your ~/Library/Services folder as mentioned above, and you should find it in the ‘Quick actions’ submenu if you right-click on a PDF.

Update Sept 2023

Some people were seeing a final PDF that was blurry. I’ve changed the way the individual pages are combined back into a single PDF, which should fix this. It works on my Mac running Ventura 13.5.

For MacOS 13 and later:

Enjoyed this post? Why not sign up to receive Status-Q in your inbox?

170 Comments

You can also use Adobe Reader which has a booklet printing option.

You are awesome!! Thanks for the software update. Cheers from Czechia.

Hi,
In the new script(MacOS 12.3 and later), the final booklet is greyed out.
Can you fix this?

    Hi RF –
    That’s one I haven’t heard before, and it doesn’t happen for me… (I’m still on Monterey – haven’t tried Venture yet.)

    A greyed-out booklet.pdf probably means some issue with your permissions to access the file on your desktop. I think the only way that would be likely to happen would be if the script was running as a different user from you, or if your desktop or the underlying filesystem had some slightly unusual configuration.

    If you right-click on it and choose Get Info..., does it tell you anything helpful under the Sharing & Permissions section?

      I also had the same result. Works as expected other than the end-result image is like washed out as if the brightness is turned all the way up, but there’s no way to undo it. I ended up using the Folder with all the PDF files split up and manually sorted them into the order I needed.

Man, you’re a legend. This helped so much! Thank you!

This has helped immensely, but I am getting non-vectored pdfs when I run the script. I start with a crisp vector PDF and after I run the script the text all becomes blurry, low quality, and non-vectored in the booklet. Is there a workaround to this or am I missing a step?

Wow! That is so cool!
It’s working perfectly on my Ventura Mac.
Thanks a lot for that awesome script and all your work.

I’m running Ventura 13 on my Mac, so I downloaded your latest version, installed it. But there is no way to access it or run it. When I right click on the pdf in finder, there is no option to do so. Yes, I restarted. I’m stumped. I’d like to run the automator on my pdf document, but there is no evident way to do so. Help!

This is working brilliantly – thank you for making it

Hello
It seems to me it will work but the script need python 3 to be installed. It’s a trouble on my “small disk” macbook air.

It there another way to execute the python 3 part of the script?

Thanks

When asking terminal for python3 Sonoma ask for developer tools to be installed… I do not use xcode these days. And i can not afford the 10Gb it needs on my tiny 256Gb disk.

    Ah, interesting. That’s a pity if they want that. Though I think it probably only needs the command-line tools, not the whole of Xcode? Don’t know how big that would be…

    No, I don’t really use Xcode any more either. I’m guessing that installing python3 using Homebrew or the installer from Python.org would be much smaller.
    I’ll update the post, though, so that people know.

I am afraid it come from my Sonoma version. I can remeber having installed Xcode back in the time and uninstalled it….

I’ve just downloaded and installed python 3.12 from python.org

It’s running but your automator still block on an xcode realted message

Thanx for your help

I plan to buy a brand new macbook next week i will try to figure it out on the brand new machine.

    OK – let me know how you get on!

    If you open the automation with Automator (by finding it under ~/Library/Services, and doing an ‘Open with…’), you can see the ‘Run Shell Script’ step which tries to find python3, by using your existing PATH with ‘/usr/bin:/usr/local/bin:/opt/homebrew/bin’ appended to the end.

    It may be that your python3 which is triggering the error is earlier on your path, and you could make things work by changing that line to make sure it finds the officially-installed version first.

THANK YOU THANK YOU THANK YOU!!!!

Not sure if I said it, but … THANK YOU THANK YOU!!!

And just in case that’s not enough … THANK YOU THANK YOU!!!

OOI, this is a completely standard “thing” on Windows 98 (which is probably the last time I ever did any printing).

Was this A5 Booklet feature ever a “thing” on MacOS? If so, where/when did it go?

Also, I am a computer programmer and so would be happy to help contribute time/effort to making an open source app/script that works on all versions of MacOS. At its core, I think it is:

Get PDF
Count pages
Add blank pages to make pages % 4 = 0 (this would be truly blank pages, not “This page has been intentionally left blank”).
Generate pages in last, first, last-n, first-n, until first-n+1 = last-n (I think that’s right).
Output to a new file based upon the same name as the original but with -A5Booklet appended to the name.

Obviously, I got THAT wrong!

Page count : 4 – Sheets : 1 – Order : [4,1,2,3]

Page count : 8 – Sheets : 2 – Order : [8,1,2,7], [6,3,4,5]
Page count : 12 – Sheets : 3 – Order : [12,1,2,11], [10,3,4,9], [8,5,6,7]
Page count : 16 – Sheets : 4 – Order : [16,1,2,15], [14,3,4,13], [12,5,6,11], [10,7,8,9]
Page count : 20 – Sheets : 5 – Order : [20,1,2,19], [18,3,4,17], [16,5,6,15], [14,7,8,13], [12,9,10,11]
Page count : 24 – Sheets : 6 – Order : [24,1,2,23], [22,3,4,21], [20,5,6,19], [18,7,8,17], [16,9,10,15], [14,11,12,13]
Page count : 28 – Sheets : 7 – Order : [28,1,2,27], [26,3,4,25], [24,5,6,23], [22,7,8,21], [20,9,10,19], [18,11,12,17], [16,13,14,15]
Page count : 32 – Sheets : 8 – Order : [32,1,2,31], [30,3,4,29], [28,5,6,27], [26,7,8,25], [24,9,10,23], [22,11,12,21], [20,13,14,19], [18,15,16,17]
Page count : 36 – Sheets : 9 – Order : [36,1,2,35], [34,3,4,33], [32,5,6,31], [30,7,8,29], [28,9,10,27], [26,11,12,25], [24,13,14,23], [22,15,16,21], [20,17,18,19]
Page count : 40 – Sheets : 10 – Order : [40,1,2,39], [38,3,4,37], [36,5,6,35], [34,7,8,33], [32,9,10,31], [30,11,12,29], [28,13,14,27], [26,15,16,25], [24,17,18,23], [22,19,20,21]

Sorted that out!

    Hi Richard –

    Yes, that’s basically right. If you grab the download, right-click and do ‘Open with… > Automator’, you can see the Python code embedded in the script, which generates those sequences (though I started the numbering from zero).

    Improvements welcome! The main issue, as you’ll have seen from the comments, is that I wrote the core of this in Python, and the version and location of the python executable has changed a few times over the years with the OS release. I wanted to create something that people could just run without having to install any other libraries, but it might have been easier to package it up with py2app or similar!

    Given that it’s only a very small bit of python in the middle, I could probably rewrite it as a bash script… Or, actually, I see that Automator now has a ‘Run JavaScript’ action; I should probably switch to that, but I wonder which OS versions have that.

    I might try it.
    Q

Thanks for doing this!

Does this service do anything more than the ‘layout –> Pages per Sheet –> booklet’ setting in Preview’s print dialogue (I’m using Ventura)? That’s great for printing A5 booklets from A4 sources, but doesn’t work properly for smaller source documents, because (ludicrously) it places the booklet pages in the middle of their respective half-page rather than together in the middle of the A4/letter sheet. I want to print tiny things (rules booklets for small games) and it feels like this should be achievable with just a little tweaking (which might be within my powers given that I previously made a hideous hack to combine parts of different pdf pages, but if there’s an actual coder out there they’re probably a better choice.

Having a really functional booklet creator on a quick action would be very life-enhancing for me.

    Hi Alison –

    Ah, thanks for pointing out that item at the bottom of the ‘Pages per sheet’ – it’s easy to miss and I hadn’t found it! I wonder when it was added… (Though it sounds as if it has some limitations, too.)

    Essentially, the only thing my script does is to rearrange the pages into the right order. The individual pages are still the A4 pages you would have had otherwise, and it’s then up to you to print them out double-sided with two pages per sheet… I expect you might have more control as a result… but you might need to employ some more tools.

    One thing I tried just now was to (a) print 2 pages per sheet but, under ‘Paper Handling’, scale to a destination paper size of A5, and select the PDF menu at the bottom to ‘Open in Preview’. This gives you a PDF with two small pages within each A5 page. Then (b) print that, but setting the Scale to 100%, which means that you get the two small pages in the middle of the A4 sheet, which I think is what you wanted?

    Quentin

Yes, that would probably do the trick, thank you!

It works like a charm – thank you very much for your effort.

You are amazing. Thank you so much!

Hi.

Firstly, THANKS! This is a great script.

However, as some other users have commented on, I find that the ‘booklet.pdf’ is of low quality / fuzzy.

Any idea what’s going wrong?

Hi
Re: my previous post.

Apologies. I’ve downloaded the correct version now (2023).

It’s now exported to the correct quality.

However, it’s upside down!

Cheers, Jason.

Any idea what this might be? Or does it not matter?

    Upside down? Now that’s one I haven’t heard before! Does it do it for all documents, or just some?
    As you say, it may not matter… but it depends exactly when things got inverted: before or after the re-ordering. The easiest way to check is probably to try it with something short! (Perhaps 8 pages with a number on each?)

Hi. I’ve tested on other PDFs and it’s fine – so it seems that it only occurs on one document I have. Very odd.
It’s 60 pages long by-the-way.

    One way you can sometimes turn PDFs into more predictable PDFs is to open them in Preview and then do ‘File > Print… > PDF’ – might be worth a try? (I also use this if I need to convert a PDF with a password into one that doesn’t have a password.)

Yes! – that works.
Thanks again. 🙂

Just so I can show off a little. Here is some PHP code that shows the mechanism of calculating the page order from the original PDF.

https://3v4l.org/Ov06C

Thanks – works like a charm!

Thank You, just what I needed, as I can’t manage to do it in Pages (Ventura) But, it makes the booklet folder with the pages in it then I get this message – The action “Run Shell Script” encountered an error: “xcrun:error: invalid active developer path (/Library/Developer/CommandLine Tools), missing xcrun at /Library/Developer/CommandLineTools/usr/bin/xcrun”

Can anybody help?

thank you, searched and fixed, nows works fine.
Thank you again

cheers
Heinz

I encounter error and Python3 crashed. No of pages in PDF is 8
The action “Run Shell Script” encountered an error: “Fatal Python error: initfsencoding: unable to load the file system codec, sys.path = [‘/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python37.zip’, ‘/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7’, ‘/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/lib-dynload’]
LookupError: no codec search functions registered: can’t find encoding

Current thread 0x00007ff856799dc0 (most recent call first):
-: line 20: 15933 Abort trap: 6 python3 – “$@” <<‘EOF’
import sys

pages = sys.argv[1:]
if len(pages) % 4 != 0:
sys.stderr.write(“Page count of PDF needs to be a multiple of 4.”)
sys.stderr.write(“You can append blank pages using Preview if needed. Select the last page and choose ‘Edit > Insert > Blank Page’.”)
sys.exit(1)

final_page_num = 4 + 4 * ((len(pages)-1) // 4)
print(final_page_num)

for i in range(0, final_page_num // 2, 2):

Here’s the sequence of 4 pages we need to combine

for this double-sided sheet.

print(pages[-(i+1)])
print(pages[i])
print(pages[i+1])
print(pages[-(i+2)])
EOF

    Hi Serge –

    I did a quick search for the key parts of your error message, and I think it’s probably an issue with your Python installation, or perhaps with some environment variables you have set? (PYTHONPATH or PYTHONHOME, perhaps?)

    Quentin

Got Something To Say:

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

*

© Copyright Quentin Stafford-Fraser