I have a problem that is bothering me for quite a while. I would like to insert a couple of pdfs automatically as attachments to a document. The user copies a bunch of pdfs in a folder, where he finds a .bat file that will create the attachments.tex document from all files automatically. The process is automated pretty far, the .bat creates a \section{} element for every pdf, too, checks for signs incompatible with Latex and removes them, such as $, & or spaces and so on.

Because it is doing all by itself already, I don't want to bother the user with the parameters of the inlcudepdf command. So, landscape documents should be included on landscape paper automatically.

I could do that by using the command


Unfortunately, there are often pretty large drawings (A3,A2 paper). So I would like to have them scaled down to A4. Using the command


I was able to have them all scaled down to A4 and automatically rotated, which is close to what I was looking for and the best solution so far.

What I cannot find is a scale down to A4, without a rotation for oversize pages. The parameter 'landscape=true' needs to be set manually for all landscape documents at the moment, which is tedious. Basically what I would need is parameter for pdfpages like


Unfortunately, this does not exist. Is there any workaround with the pdfpages package itself which I just did not think of?

1 Answer 1


Here is a solution. We use pdftex primitives \pdfximage and \pdflastximagepages



\includepdf[pages=\themtpdfpage, landscape]{attachment.pdf}%
  • Wow, thank you! I see that I have still years ahead of me to become nerdy enough to get this stuff myself, but it is exactly what I needed!
    – Tilman
    Mar 18, 2016 at 8:46
  • Unfortunately, I encountered a problem with the solution: It does rotate and scale the pages as expected, but it drops the last page of every document longer than one page.
    – Tilman
    Apr 11, 2016 at 11:53
  • I figured out that it is because of the last \ifnum command. It should compare mtpdfpage less or equal to pdflastximagepages. I couldn't find the correct way to specify less or equal, so I inserted a second counter mtpdfpageless, which starts with the value 0. In the end, I just compare mtpdfpageless<\pdflastximagepages. It works, but it's not a beautiful solution. Is there a better way?
    – Tilman
    Apr 11, 2016 at 12:02
  • @Tilman sorry, may bad. I edited the answer.
    – touhami
    Apr 11, 2016 at 15:16

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.