[Tex/LaTex] How to autorotate pdflscape landscape pages when n-upping

pdfpdflscape

I'm using pdflscape for my landscape pages in an A5 portrait document. Then I use the following command line to prepare the PDF to be printed on A4 paper:

pdftk blank.pdf document.pdf output padded_document.pdf verbose && pdfnup --paper a4paper padded_document.pdf

The resulting padded_document-nup.pdf, however, has all the landscape pages still in landscape in what amounts to an A6 format, instead of having them rotated and in A5.

Is there a way to automatically rotate them so they will appear in the intended size? I know I could replace pdflscape by lscape but I keep forgetting that and it'd be nice to have a solution that doesn't involve changing my document each time I want to print it. So either a clever trick in the PDF or something I can put in my command line.

\documentclass[a5paper]{article}
\usepackage{mwe}
\usepackage{pdflscape}
\begin{document}
\blindtext\blindtext
\begin{landscape}
\thispagestyle{empty}
\begin{figure}
\includegraphics[width=\linewidth]{example-image-a}
\caption{Landscape figure}
\end{figure}
\end{landscape}
\blindtext\blindtext

\blindtext\blindtext
\end{document}

Which as 4-up with page borders (not the desired 2-up without borders but you get the idea) looks like this:

3 portrait, 1 landscape

What it should look like is this:

4 portrait
I faked this last one by just using lscape instead of pdflscape.

Best Answer

pdfnup uses pdfjam, which in turn uses the LaTeX package pdfpages. The latter one knows the option rotateoversize, from the documentation:

This option allows to rotate oversized pages. E.g. pages in landscape orientation are oversized relatively to their portrait counter- part, because they do not match within the contour of a portrait page without rotating them. By default oversized pages are scale and are not rotated. Either true or false (or no value, which is equivalent to true). (Default: rotateoversize=false)

This option can be specified on the command line for pdfnup or pdfjam:

$ pdfnup --paper a4paper --rotateoversize true test.pdf

Page 1 Page 2

Related Question