Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I tried to include a PDF page using the pdfpages package — this works well for a standard case, f.e. (t.pdf is the first page of the PGF manual):

\documentclass{scrartcl}
\usepackage{geometry}
\geometry{papersize={155mm,220mm}}
\usepackage{pdfpages}
\usepackage{lipsum}

\begin{document}
\lipsum[1-2]
\includepdf{t.pdf}
\end{document}

This code produces the following output:

Output of the first MWE.

In my case, my printer needs an additional trimming edge, since I use full-page images. For all other publications (there was no need to include other PDF files) I used the very comfortable option layoutsize in combination with papersize of the geometry package. Unfortunately, if I use this option, the pdfpages package does ignore it (exaggerated by intention):

\documentclass{scrartcl}
\usepackage{geometry}
\geometry{papersize={200mm,300mm}, layoutsize={155mm,220mm}}
\usepackage{pdfpages}
\usepackage{lipsum}

\begin{document}
\lipsum[1-2]
\includepdf{t.pdf}
\end{document}

This produces the following output:

Output of the second MWE

As you can see, the layout of the text content is untouched, but the included PDF is scaled to the paper size, not to the layout size. Is there a possibility to include a PDF file while respecting the layout size given by the geometry package?

Thank you for your help in advance.

Edit: I have forgotten to take the layoutoffset option of the geometry package into account in my question. A solution should not only respect the given layout size, but also its offset specification.

\documentclass{scrartcl}
\usepackage{geometry}
\geometry{papersize={200mm,300mm}, layoutsize={155mm,220mm}, layoutoffset={10mm,5mm}}
\usepackage{pdfpages}
\usepackage{lipsum}

\begin{document}
\lipsum[1-2]
\includepdf{t.pdf}
\end{document}
share|improve this question
    
Why don't you edit also the example code to show your real options to geometry? –  egreg Mar 6 '12 at 9:05
    
@egreg: Because my screenshots would not suit any longer. Because of this circumstance, I added a code example at the end of my question, but I think that's only a trivial addendum. –  DigNative Mar 6 '12 at 9:16

2 Answers 2

up vote 4 down vote accepted

You can pass the layout width and height (of course you can use the figures you know, but this is independent from them):

\makeatletter
\includepdf[
  pages=1,
  width=\Gm@layoutwidth,
  height=\Gm@layoutheight,
  offset={\dimexpr(\Gm@layoutwidth-\paperwidth)/2\relax}
         {\dimexpr(\paperheight-\Gm@layoutheight)/2\relax},
  keepaspectratio
  ]{pgfmanual.pdf}
\makeatother

Of course it won't be perfect unless the proportions of the layout dimension are the same as that of the PDF you're including.

share|improve this answer
    
Thank you for your answer; that's the solution I'm searching for. I supposed that it would be necessary to get the geometry-specified parameters, but I had no idea how to do that. In order to take the layoutoffset option additionally into account (I realized that after your answer), I changed {\dimexpr(\Gm@layoutwidth-\paperwidth)/2\relax} to {\dimexpr(\Gm@layoutwidth-\paperwidth)/2+\Gm@layouthoffset\relax} and {\dimexpr(\paperheight-\Gm@layoutheight)/2\relax} to {\dimexpr(\paperheight-\Gm@layoutheight)/2-\Gm@layoutvoffset\relax}. Thank you really much for your help! –  DigNative Mar 6 '12 at 9:08

The pdfpages manual says

Internally the command \includepdf makes use of the \includegraphics command from the graphicx (actually graphics) package. Hence it is possible to use all the options of \includegraphics, too. Options which are not interpreted by \includepdf are passed directly to \includegraphics.

Hence, you can set the width and height directly.

\documentclass{scrartcl}
\usepackage{geometry}
\geometry{papersize={200mm,300mm}, layoutsize={155mm,220mm}}
\usepackage{pdfpages}
\usepackage{lipsum}
\begin{document}
\lipsum[1-2]
\includepdf[width=155mm,height=220mm]{pgfmanual.pdf}
\end{document}

You might want to look at the offset option, which changes the position of the inserted pdf page.

The geometry package stores the page dimensions using macros that start with \Gm@, so layoutheight is stored in \Gm@layoutheight, etc. The easiest way to use these is probably to create a custom macro.

\makeatletter
\newcommand\myincludepdf[1]{\includepdf[width=\Gm@layoutwidth,height\Gm@layoutheight{#1}}
\makeatother

...

\myincludepdf{pgfmanual.pdf}

If you want to position the included page differently, you could do something similar with the layout offsets from geometry and the offset option for \includepdf.

share|improve this answer
    
Hi, thank you for your answer. I'm aware of the graphicx options for \includepdf. Unfortunately, you describe only a manual (partial) solution for this issue, but is there a way to automate \includepdf just to respect the options of geometry (f.e. layoutoffset)? I can't imagine that this use case is so unusual. Your MWE gives an embedding of the first page of the PGF manual, which is centered on the page (strictly speaking, this is not an answer to my question). –  DigNative Mar 5 '12 at 22:28
    
I have edited my answer. You might want to edit your question as well, because it does not mention offsets. –  Ian Thompson Mar 5 '12 at 23:18
    
Thank you for your addendum, now the scaling is automated, but not the proper positioning (top left corner). Apart from that I've forgotten to take the layoutoffset into account in my question; I will change that. –  DigNative Mar 6 '12 at 8:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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