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, 2017 at 10:57
  • 1
    Try adding fitpaper=true to the \includepdf keys. You might also need templatesize={}{}.
    – Ross
    Oct 12, 2017 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. Oct 12, 2017 at 11:14
  • 1
    You could use option rotateoversize. See also tex.stackexchange.com/a/167912/43317
    – esdd
    Oct 12, 2017 at 11:38
  • 1
    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! Oct 12, 2017 at 11:41

1 Answer 1


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.

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



    \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}}%


Hope that helps!

  • 1
    I used Andreas's code, and had to make the following changes. I would have put this in a comment, but don't have enough reputation points for that :/ without pages=- it was only printing the first page of the pdf. I've also reversed the dimensions for the landscape version of the code so that the landscape pages don't get rotated sideways. I don't see what difference rotateoversize makes. \newcommand{\addpdf}[1]{% \sbox{\temp}{\includegraphics{#1}}% \setlength{\tempwidth}{\widthof{\usebox{\temp}}}% \setlength{\tempheight}{\heightof{\usebox{\temp}}}% \ifthenelse{\tempwidth > \tempheight}
    – Dotno
    Mar 2, 2023 at 5:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .