Longer post
I'm using double flopping/reflecting method. It requires several steps, please use pdflatex
or lualatex
. The example below could be slightly modified to be used with xelatex
, please see How to automatically output page order to print 8 pages of a booklet on a single sheet of Letter paper?, where I used \XeTeXpdfpagecount
instead of \pdfximage
and \pdflastximagepages
. Then all three major LaTeX engines could be run.
Step 1: The materials to be printed
I am emulating 32 unrelated business cards with both sides typesetted. We will try to print 4x4 of them on A4 papers, duplex and long edge printing. I enclose the TeX code (mal-pdf-part1.tex
) and a preview of the first eight pages (of 64).
% run: any LaTeX engine mal-pdf-part1.tex
\documentclass[a4paper,landscape]{article}
\paperwidth=0.25\paperwidth
\paperheight=0.25\paperheight
\pdfpagewidth=\paperwidth
\pdfpageheight=\paperheight
\usepackage{tikz}
\begin{document}
\newcount\malc
\malc=0
\loop
\advance\malc by 1
\foreach \mcolor/\mside in {green/front,blue/back} {%
\newpage
\pagecolor{\mcolor}%
\begin{tikzpicture}[remember picture, overlay]
\node[font=\bfseries,scale=10,yshift=0.8mm] at (current page) {\the\malc}; % front side
\node[font=\bfseries,scale=4,yshift=-4mm] at (current page) {\mside{} side}; % back side
\end{tikzpicture}%
}% End of \foreach...
\ifnum\malc<32\repeat % E.g. a number of business cards...
\end{document}

Step 2: Rearranging the odd pages (the front/recto pages)
Generally speaking, we only need to select them (step 2a) and use basic nup=4x4
in the pdfpages
package (step 2b). I enclose both TeX files and a preview of the PDF files.
This is the mal-pdf-part2a.tex
file (preview consists of 8 pages of 32):
% run: pdflatex or lualatex mal-pdf-part2a.tex
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\def\malfile{mal-pdf-part1.pdf}
\pdfximage{\malfile}
\newcount\malc \malc=0
\loop
\advance\malc by 1%
\ifnum\malc<\pdflastximagepages
\ifodd\malc\else
\includepdf[fitpaper,pages={\the\malc},angle=90]{\malfile}
\fi
\repeat
\end{document}

And this is the mal-pdf-part2b.tex
file:
% run: pdflatex or lualatex mal-pdf-part2b.tex
\documentclass[a4paper]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages={-},nup=4x4,frame]{mal-pdf-part2a.pdf}
\end{document}

Step 3: Rearranging the even pages (the back/verso pages)
In step 3a we are selecting even pages, rotating them (-90 degrees for long-edge printing, 90 degrees for short-edge printing, if needed) and reflecting them for the first time. This is the mal-pdf-part3a.tex
file and a preview of the first eight pages of 32:
% run: pdflatex or lualatex mal-pdf-part3a.tex
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\def\malfile{mal-pdf-part1.pdf}
\pdfximage{\malfile}
\newcount\malc \malc=0
\loop
\advance\malc by 1%
\ifnum\malc<\pdflastximagepages
\ifodd\malc
\includepdf[fitpaper,pages={\the\malc},angle=-90,reflect]{\malfile}
% We would use angle=90 for short-edge duplex printing.
% We use angle=-90 for long-edge duplex printing.
\fi
\repeat
\end{document}

And this is the mal-pdf-part3b.tex
file:
% run: pdflatex or lualatex mal-pdf-part3b.tex
\documentclass[a4paper]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages={-},nup=4x4,frame]{mal-pdf-part3a.pdf}
\end{document}

Step 4: Putting PDF files together
Our last step is to put those two PDF files together. The final PDF file consists of 4 pages (2 A4 papers) in the end. As we can see we are reflecting the back pages one more time. It's happening after the rearranging step, therefore the rectangles will start fitting to each other after printing.
I enclose the last TeX source code and a preview of the final PDF file. This file is ready to be printed (long edge, duplex, A4 paper) and cut into 16 pieces per paper afterwards.
In production we must be careful that there is usually 5 milimeters space around the page where printer cannot print due to technical limitations (office laser and ink printers). We usually use the scale parameter (twice in this example) in this final step. I'm using scale=1
in this example, in production I usually use scale=0.92
.
% run: pdflatex or lualatex mal-pdf-part4.tex
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\def\malfile{mal-pdf-part2b.pdf}
\pdfximage{\malfile}
\newcount\malc % inicialization of page counter
\malc=0 % setting the counter
\loop
\advance\malc by 1%
\includepdf[fitpaper,pages={\the\malc},scale=1]{mal-pdf-part2b.pdf} % 0.92 in production
\includepdf[fitpaper,pages={\the\malc},reflect,scale=1]{mal-pdf-part3b.pdf} % 0.92 in production
\ifnum\malc<\pdflastximagepages\repeat
\end{document}

Closing notes
In this example, we are running:
pdflatex mal-pdf-part1.tex
pdflatex mal-pdf-part1.tex
pdflatex mal-pdf-part2a.tex
pdflatex mal-pdf-part2b.tex
pdflatex mal-pdf-part3a.tex
pdflatex mal-pdf-part3b.tex
pdflatex mal-pdf-part4.tex
We can easily change the nup
parameter from 4x4
to anything we like, however, a change would be required in mal-pdf-part2b.tex
and also in mal-pdf-part3b.tex
.
We don't use frame
parameter (the same two files) in production.
If we need to enter an empty page somewhere in the middle of the document, we usually use \newpage\mbox{}
in the first step (twice as we typeset front and back pages).
If we enter less papers (<32 in this example) in mal-pdf-part1.tex
then the remaining space will be empty. Due to the double reflecting method the empty space will also fit. I enclose an example where I entered 30 pages instead of 32.
