0

I have a bunch of pdfs in a folder, some landscape, some portrait (so far none that are a mix, but it's possible) I have a script to add the required \includepdf statements for each pdf file. This generated tex file is then included in my main tex file.

I want the pdfs to appear at about 90% scale and for landscape pages to be rotated. So, I have the following

\includepdf[scale=0.9, frame, pages=-, pagecommand=\thispagestyle{pdffooter}]{"my file".pdf}

This gets the portrait pages in as I want them, but the landscape ones come out like this and still need rotating.

lanscape page.

I've tried various options to auto rotate the landscape pages but it seems they don't work in conjunction with the scale option. Since I am using a script to insert these '\includepdf' statements, I don't know in advance which pages need to be rotated.

Any ideas?

  • Basically, I would put each PDF in an \sbox and check if the width of that box is greater than its height. If so, include the rotated picture, otherwise include it in its current form. The assumption is that the PDF pages are "clean" -- cropped to the size of content, so that no empty borders falsify the result. I'll try to come up with working code later on. – Andreas Oct 12 '17 at 10:57
  • Try adding fitpaper=true to the \includepdf keys. You might also need templatesize={}{}. – Ross Oct 12 '17 at 10:58
  • fitpaper leaves the inserted pdf as-is and changes the containing pdf page orientation. If I add the template size option to force it back to portrait dimensions, I'm back to where it was before. – user2285589 Oct 12 '17 at 11:14
  • You could use option rotateoversize. See also tex.stackexchange.com/a/167912/43317 – esdd Oct 12 '17 at 11:38
  • So I now have \includepdf[fitpaper, templatesize={210mm}{297mm},rotateoversize=true, frame=true, scale=0.83... This works on the landscape pages but it's now rotating the portrait pages! – user2285589 Oct 12 '17 at 11:41
2

The following code is a bit of a kludge as it uses \includegraphics for determining the dimensions of a page before printing the document with \includepdf. Also, it does not handle a mix of portrait and landscape pages in one document.

\documentclass{article}
\usepackage{pdfpages}
\usepackage{graphicx}       % We need that for determining PDF dimensions

\newsavebox{\temp}
\newlength{\tempwidth}
\newlength{\tempheight}

\newcommand{\addpdf}[1]{%
    \sbox{\temp}{\includegraphics{#1}}%
    \setlength{\tempwidth}{\widthof{\usebox{\temp}}}%
    \setlength{\tempheight}{\heightof{\usebox{\temp}}}%

    \ifthenelse{\tempwidth > \tempheight}
        {\includepdf[fitpaper, templatesize={210mm}{297mm},rotateoversize=true, frame=true, scale=0.83, landscape]{#1}}
        {\includepdf[fitpaper, templatesize={210mm}{297mm},rotateoversize=true, frame=true, scale=0.83]{#1}}%
}


\begin{document}
\addpdf{example-image-a4.pdf}
\addpdf{example-image-a4-landscape.pdf}
\end{document}

Hope that helps!

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.