# How to sort the order of pages so that they can be printed in a folded book?

I am using ConTeXt to print a book. Each page is A5, but the print store can only print on A4 paper, so they print 2 pages on each side of the A4 paper. I used this code to specify the layout:

\setuppagenumbering[location=bottom, alternative=doublesided]
\setuppapersize[A5]


The print store does not know how to properly sort these A5 pages for printing. They requested I give them a PDF set for A4 paper, already sorted properly. If there are 100 pages, then the first piece of paper would look like this:

(front of 1st paper)
________ ________
|        |        |
|        |        |
|        |        |
|__100___|____1___|

(back of 1st paper)

________ ________
|        |        |
|        |        |
|        |        |
|____2___|___99___|


The second piece of paper would look like this:

(front of 2nd paper)
________ ________
|        |        |
|        |        |
|        |        |
|___98___|____3___|

(back of 2nd paper)
________ ________
|        |        |
|        |        |
|        |        |
|____4___|___97___|


The pages are then assembled like this:

      /|=====>>/|=====>>/|
100->/ |  98->/ |  96->/ |
/  |     /  |     /  |
/ 99|    / 97|    / 95|
|\  |    |\  |    |\  |
| \ |    | \ |    | \ |
|  \     |  \     |   |
|   |    |   |    |   |
| 1 |    | 3 |    | 5 |
\  |     \  |     \  |
\ |<-2   \ |<-4   \ |<-6
\|=====>>\|=====>>\|


I have tried internal options in ConTeXt and pdfbook, but I cannot see any options which sorts the pages in this way.

-
Common PDF viewers should be able to print a document as booklet without rearrangement of the pages. – Thorsten Donig Jun 23 '12 at 9:44
I know that the Adobe software used at the print store can do this, however, I must give the PDF to another person who will take it to the printing store. Both them and the printing store workers do not know how use these features of the software. I need to prepare the PDF in advance, so it is as simple as possible for them to just print the pages double-sided. – Village Jun 23 '12 at 9:52
Why not use the booklet printing feature of the document viewer you describe and then "Print to PDF file"? On Windows there's a tool kalled FreePDF that installs a PDF "printer" and on Ubuntu it should work out of the box. – Fritz Jun 23 '12 at 10:49
If that's a serious print shop they don't need any instructions. Other than that heavy duty printers have the option to select booklet printing. If even that is not the case Adobe Reader is easy enough to use. Probably you can make an instruction document showing the steps to follow. – percusse Jun 23 '12 at 11:00
I use the very same page setup for a song booklet in my parish. :) The booklet is typeset in a a5 paper and then I use pdfpages in the resulting .pdf with \includepdf and the pages={} option (I use pdflatex). The page order is defined by this humble Python script I wrote to help me with this task. :) – Paulo Cereda Jun 23 '12 at 11:08

Edit:
I just noticed, buried in the comments under your question, that the pages will be cut rather than folded. In that case signature size does not matter, \setuparranging[2UP] is the way to go, and you can forget about \setuppageshift because that is only needed when folding. But perhaps my answer will be of interest to somebody else.

## How large do you want your signature?

A 'signature' is a number of pages that is folded and bound together; books are generally made up of multiple signatures. Each signature is held together by stitching (or glue), and the signatures are then attached to a ribbon or somesuch and get a cover put around them. I'm no expert, as you no doubt can tell.

The arrangement you were thinking of, 2UP, sets the signature size equal to the number of pages. In your case, that's 100 pages. You'll have 4 pages on each sheet (2 on the front, 2 on the back), so that equals 25 sheets. That is really quite large — try taking 50 pages (25 sheets) from a nearby book and bending them in the middle. (Don't fold them, please. Not even if you can. ;-)) So I propose you use a smaller signature, if that is possible for you.

### Four-sheet (sixteen-page) signatures

ConTeXt provides the predefined arranging 2*2*4. It is like 2UP, but for 4-sheet signatures; each block of 16 pages is arranged as follows.

16   1    % sheet 1 recto
2    15   % sheet 1 verso, so 2 will lie under 1
...  ...
10   7    % sheet 4 recto
8    9    % sheet 4 verso, so 8 wil lie under 7


Use it like this:

\setuppapersize[A5][A4, landscape]
\setuparranging[2*2*4]


It is mentioned among the other imposition schemes on page 13-14 of the new manual chapter on page design. Link obtained from the main page of the wiki.

### Custom signature sizes

See the Lua code on the last section of the Imposition page. I don't know what signature size is still safe — grab some sheets of paper, and see what still folds nicely.

## Offsetting pages because the outermost sheet is wrapped more thickly.

On page 33 that manual chapter mentions the following:

There is culprit in arranging pages. If multiple layers of paper are folded, the outermost paper will require more width because it has to turn around the inner paper layers. This effect occurs as well in the spine folds as also in the head folds. How much width is required depends on the number of folds and the thickness of the paper. In professional book printing this effect is accounted for by displacing the pages depending on their position in horizontal and vertical direction. The result is that there will be a perfect look-through registering of all pages. There are no simple rules to indicate the required amount of displacement. Mostly it is a matter of experience to set up the page shift information.

This is the pageshift code the book then gives. I've looked at how it shifts the pages if you use 2*2*4 arranging (by turning 0.25 / 0.15 / 0.05 mm into 12 / 8 / 4 mm, because I don't like squinting), and at least the directions and relative magnitudes are right. I have no clue whether these are reasonable values for standard printer A4 paper, but I would assume they are.

\definepageshift[Hor][horizontal]
[0.25mm,  % page 1
-0.25mm,  % page 2
0.15mm,  % 3
-0.15mm,  % 4
0.05mm,  % 5
-0.05mm,  % 6
0mm,     % 7
0mm,     % 8
0mm,     % 9
0mm,     % 10
0.05mm,  % 11
-0.05mm,  % 12
0.15mm,  % 13
-0.15mm,  % 14
0.25mm,  % 15
-0.25mm]  % 16
\setuppageshift[paper][Hor]  % use the list we just defined

-

It is probably easier to post-process the PDF. TeXLive contains a tool called pdfbook that does this:

pdfbook --batch example.pdf


will create a example-book.pdf with the pages resorted and 2-on-1. In case you create postscript output, there is also a psbook.

Edit: Maybe your pdfbook is too old? Mine produces a perfect Booklet-PDF with out any extra parameters.

-
This sorting arrangement is different than what I described. I think this sort order would require much manual sorting of the pages after they are printed. – Village Jun 23 '12 at 10:14
It does produce the order you requested. The only difference to your quoted example is, that each odd page (e.g. the 100-1) is rotatet 180 degree so that if printing duplex via long edge, the correct front and back sides of each page fit together. At least in the version I use from TexLive 2011. – TeXter Jun 23 '12 at 10:18
I have pdfjam 2.05. It is not putting the last page on the same side as the first page. – Village Jun 23 '12 at 10:27
I have 2.08, mine does. How many pages does your pdf have? An uneven number or not a multiple of 4? You need a multiple of 4 for this to work. – TeXter Jun 23 '12 at 10:31
A booklet (in general, not only for pdfbook) must have a multiple of 4, as each physical sheet of paper produces in the end 4 pages. pdfbook adds empty pages to the end of your document. – TeXter Jun 23 '12 at 10:36

I think I have found a solution which solves the problem within ConTeXt:

\setuppagenumbering[alternative=doublesided]
\setuppapersize[A5][A4, landscape]
\setuparranging[2UP]


I appears to properly sort the pages, but I must have some mistake in the settings, because it seems to make all of "front" sides of papers as recto and "back" sides of paper as verso, even though each side does not truly correspond to this. Perhaps that is not important as printers might not know the difference.

-
Does this really put pages 1,2,99,100 on the same sheet of paper? – Loop Space Jun 23 '12 at 17:05
Yes, it does, although I still think the code is not correct. – Village Jun 23 '12 at 18:30
What is the problem with "makes the 'front' sides recto and the 'back' sides verso"? Surely that is exactly right? At least it is conventional that if you stack the sheets the side [100| 1] is on top, with 2 on the obverse 'under' 1 and 99 'under' 100. I.e. of the four pages on a sheet, the outermost are on the recto side. – Esteis Jun 23 '12 at 22:04

You can use pdfpages package with its signature option.

Here is an example where original A5 document (doc-a5.pdf) must contain 100 pages.

\documentclass[a4paper]{book}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=-,signature=100,landscape,noautoscale]{doc-a5.pdf}
\end{document}

-
So this answer involves first compiling it (using context) and then reloading it in a LaTeX file. (Just wanting to be clear how this works) – Loop Space Jun 23 '12 at 17:05