[Tex/LaTex] How to print index cards two-sided with multiple cards per page

double-sidedpdfpagesprinting

There are several answers about "learning cards" here on Stackexchange, pointing to several solutions, but this particular part of it is not my problem. I already designed them, created them (DIN A 6) with front and back and got a PDF with consecutive pages "front : back" of each index card.

One index card with front and back side

Now I'm going to print them, and right here my problem starts.

The idea is to arrange 2×2 of those cards on an DIN A 4 paper, so I can print them with usual hardware. This is possible by using the pdfpages package postprocessing the first PDF named "cards.pdf", creating a second one:

\documentclass[landscape]{scrartcl}
\usepackage{pdfpages}

\begin{document}
\includepdf[frame, pages={1, 3, 5, 7}, nup=2x2]{cards.pdf}
\includepdf[frame, pages={6, 8, 2, 4}, nup=2x2]{cards.pdf}
\end{document}

Index cards 2x2

That works fine, but as you may have realized, I have to specify the page numbers manually, which may be a difficult task in case of a huge number of cards. There must be an easier way to achieve this.

And that's my question: How can I print those index cards two-sided with multiple cards per page in a way, that right behind the front side of one card its back side fits on the very back of the printed paper?

Best Answer

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}

mwe, part 1


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}

mwe, step 2a

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}

mwe, step 2b


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}

mwe, step 3a

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}

mwe, step 3b


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}

mwe, step 4

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.

mwe with some empty pages in it