How can I merge four A6 pages into a single A4 page?

TL;DR: How can I take four A6 pages to create a single A4 page, using the pdf crate or any other one?


Hello. I’m trying to create booklets, ie a small book that I can print using a regular printer, then fold it like a book.

Note for Americans: A4 is a paper size specification about the size of US-letter, and A6 is 4 time smaller, so you can fit exactly four A6 pages into a single A4 page.

Step 1: create the text, using any tool (like libreoffice or latex) in A6 pages. Each square in the schema bellow is an A6 page.

----- ----- ----- ----- ----- ----- ----- -----
| 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 |
----- ----- ----- ----- ----- ----- ----- -----

Step 2: reorder the pages (I already found how to do it with the pdf crate)

----- ----- ----- ----- ----- ----- ----- -----
| 8 | | 1 | | 6 | | 3 | | 7 | | 2 | | 5 | | 4 |
----- ----- ----- ----- ----- ----- ----- -----

Step 3: merge the A6 pages into A4 pages (left to right, and top to bottom). This is the step I don’t know how to do it. The schema bellow are the 2 sides of an A4 paper.

  front         back
---------    ---------
| 8 | 1 |    | 2 | 7 |
---------    ---------
| 6 | 3 |    | 4 | 5 |
---------    ---------

Step 4: print double sided, cut on the horizontal line, fold on the vertical line, and finally put the part that was previously the bottom half in the inside of the top half. You have a booklet with the pages in the right order


The same process explained with an image from internet:


As I said, I need help for the step 3. More specifically how to take an A6 pdf as input, load 4 at pages at a time, create a blank A4 page, and put those 4 pages respectively on the top-left, top-right, bottom-left and bottom-right of the A4 page, and finally generate the A4 pdf output.

I first tried to do it with the pdf crate, but it does not have any documentation and expect that you already know about the pdf specification, which is 756 pages long and I do not want to become a pdf expert, I want to write the content of the booklet!

Sebastian Köln, one of the main authors of the pdf crate tried to help me on zulip, but honestly my lake of knowledge of the pdf specification seems way to big to even start to understand how do what I was expecting to be a simple task.

I would greatly appreciate any help. It can use any other library than the pdf crate (I’m not even sure it was the right choices). It can even use hack like converting from pdf to png, then do the merge in png, and back to pdf, whatever. I would prefer to do it in Rust, but if its simpler to do it in python, so be it. As I said before, I would like to spend my time writing a story, not code. It was fun the first few hours (especially writing a generic way to reorder the pages of the source document to do a booklet, aka step 2) but now I would prefer to move on.

Thanks a lot in advance.

why don't you just use existing software to do it instead of writing you own? e.g. adobe acrobat and reader support booklet mode out of the box, make sure to check the preview image before sending to the printer:

https://helpx.adobe.com/acrobat/kb/print-booklets-acrobat-reader.html

Unless I’m mistaken, Acrobat reader only supports printing A5 booklets in A4 pages. I’ll need to print much smaller booklet, probably A6, or even A7 into A4 pages. But otherwise it would indeed would have been a much simpler solution, thanks for pointing it to me. I also searched for online tool, so far without success.

Could you convert the pdf pages to, say, png? Then you could use typst to arrange them properly on a new page of your choice.

In the past I've used GitHub - pdfjam/pdfjam: The pdfjam package for manipulating PDF files, with has a simple CLI. The downside is that it requires a latex installation.

During the years I used different tools to do imposition. The new kid on the block is pdfmixtool, that works quite well (and does not need LaTeX). See PDF Mix Tool | scarpetta.eu.

Thanks a lot for all of those suggestions, they are very welcome. I’ll be in vacation until next week, but I will take a close look at all of them when coming back