How to rotate every second page in a pdf?

I have a pdf and need to have each second page turned upside down, so that I can print it twosided. I found pdfpages rotate odd pages 180º and changing

 \foreach \p in {1,...,\the\pdflastximagepages}{%
\ifnumodd{\p}%
{\includepdf[pages=\p,angle=180]{\jobname-step1}}%
{\includepdf[pages=\p]{\jobname-step1}}%
}


to

 \foreach \p in {1,...,\the\pdflastximagepages}{%
\ifnumodd{\p}%
{\includepdf[pages=\p,angle=180]{\jobname-step1}}%
{\includepdf[pages=\p+1]{\jobname-step1}}%
}


(amongst other changes) would do the job I think. But adding the \p+1 gives an error. I tried it with the package calc, but without any luck.

• Many printer drivers can be configured to do this for you automatically (no LaTeX required). – Steven B. Segletes Sep 2 '16 at 10:48
• please, why are you doing this (\p+1) in the first place? – touhami Sep 2 '16 at 11:25

2 Answers

Try

\foreach \p in {1,...,\the\pdflastximagepages}{%
\ifnumodd{\p}%
{\includepdf[pages=\p]{\jobname-step1}}%
{\includepdf[pages=\p,angle=180]{\jobname-step1}}%
}


After some long hours I got the following to do the job:

\documentclass[landscape]{article}
\usepackage{pgffor,pgfmath,pdfpages}

\def\originalfile{backlog-grooming.pdf}

\begin{document}

\pdfximage{\originalfile}%
\foreach \p in {1,3,...,\the\pdflastximagepages}{%
\pgfmathparse{int(\p+1)}%
{\includepdf[pages=\p]{\originalfile}}%
{\includepdf[pages=\pgfmathresult,angle=180]{\originalfile}}%
}

\end{document}


In the file backlog-grooming.pdf every second page is turned upside down.