3

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.

2

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

1

Do you want something like this?

2xA5 on A4

\documentclass[a5paper]{article}
\usepackage{mwe}
\usepackage{pdflscape}
\usepackage{pgfpages}
\pgfpagesdeclarelayout{my 2up}
{
  \def\pgfpageoptionborder{0pt}
}
{
  \pgfpagesphysicalpageoptions
  {%
    logical pages=2,%
    physical height=\paperwidth,%
    physical width=\paperheight,%
  }
  \pgfpageslogicalpageoptions{1}
  {%
    resized width=.5\pgfphysicalwidth,%
    resized height=\pgfphysicalheight,%
    center=\pgfpoint{.25\pgfphysicalwidth}{.5\pgfphysicalheight}%
  }%
  \pgfpageslogicalpageoptions{2}
  {%
    resized width=.5\pgfphysicalwidth,%
    resized height=\pgfphysicalheight,%
    center=\pgfpoint{.75\pgfphysicalwidth}{.5\pgfphysicalheight}%
  }%
}
\pgfpagesuselayout{my 2up}[a4paper]
\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}
0

I hope this will be more usefull than the other one. You can convert A4 or A5 (one unique size for the input file), landscape or portrait (one orientation for the input file) to a A4 format file constitued of two A5 merged and landscape oriented pages per page.

#!/bin/bash

IFS='
'

FILE_EXT=$(echo "$1" | cut -f2 -d '.')

# Vérifier si fichier pdf
if [ "$FILE_EXT" != pdf ]
then
echo "Attention, le fichier $1 n'est pas un fichier .pdf"
exit
fi

FILE_NAME=$(echo "$1" | cut -f1 -d '.')

# Détecter la présence du fichier en .pdf
if [ ! -e "./$FILE_NAME.pdf" ]
then
echo "Attention, le fichier $FILE_NAME.pdf n'existe pas"
exit
fi

X=$(pdfinfo $FILE_NAME.pdf | grep 'Page rot:' | cut -d":" -f2)

if [ $X -eq 0 ] || [ $X -eq 180 ] ;
    then echo "portrait"
    pdftk $FILE_NAME.pdf cat 1-endright output sortie-0.pdf
    else echo "landscape"
    cp $FILE_NAME.pdf sortie-0.pdf
fi

echo '\documentclass[a4paper]{article}' > sortie-1.tex
echo '\usepackage{pdfpages}' >> sortie-1.tex
echo '\begin{document}' >> sortie-1.tex
echo "\includepdf[pages=-,nup=1x2]{sortie-0.pdf}" >> sortie-1.tex
echo '\end{document}' >> sortie-1.tex

pdflatex sortie-1.tex 

mv sortie-1.pdf "${FILE_NAME}-Sortie.pdf"
rm sortie-*
  • Thanks. However, this doesn't behave any differently than my command line for me. It doesn't rotate individual pages. – Christian May 11 '14 at 15:09
  • Then i don't understand what you exactlty want. – Tarass May 11 '14 at 15:12
  • I want all pages to have a portrait orientation, regardless of their orientation in the original document. So the brute force approach would be to split the document into individual pages, detect their orientation, rotate them 90 degrees anti-clockwise when they are in landscape, cat them back together again and 2-up them. I'm hoping there is a much easier way, though. – Christian May 11 '14 at 15:30
  • Lets try again ! ;-) – Tarass May 12 '14 at 17:43
  • Ok, I seem to struggle to make myself cleary. I added a MWE to my question, including pictures. Pictures always help, right? :) – Christian May 13 '14 at 12:27
0

If it works with lscape for printing, why don't use such a script for printing version :

#!/bin/bash

IFS='
'

cat $1 | sed "s/pdflscape/lscape/g" > Sortie-0.tex
pdflatex Sortie-0.tex
pdfnup --paper a4paper Sortie-0.pdf -o Sortie-1.pdf
rm Sortie-0*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.