6

I'd like to include some pages from a separate PDF with the right half trimmed off, but I don't know in advance the exact size of the pages. I tried a solution, using pdfpages to include from the PDF and adjustbox with the Export option to replace \includegraphics and let me use the \width macro.

However, as soon as adjustbox is included, \includepdf becomes unable to include anything other than the first page! Here is a minimal example (with my 'real intention' included as a comment):

\documentclass{article}

% Fails with Export option, works without!
% The export option solves the minimal example but breaks line marked ***
\usepackage[Export]{adjustbox}
\usepackage{pdfpages}

\begin{document}

\includepdf[pages=1]{lipsum.pdf}
\includepdf[pages=2]{lipsum.pdf}

%% The commented line is more like what I want to do, but things fail
%% even without the trim/clip!
% \includepdf[fitpaper,pages=1,trim={0 0 {.5\width} 0},clip]{lipsum.pdf} % ***

\end{document}

The example ought to just include pages 1 and 2 of `lipsum.pdf', but instead it just includes page 1 twice!

Replacing Export with export fixes the minimal example but breaks the line ***, apparently because \width is then not defined in the arguments to \includegraphics.

I can think of several workarounds for this (pdftk burst the original pdf beforehand, etc.) but does anyone know what's going on here, and whether one of the packages can be patched?

4

Note the use of the undocumented feature of \includegraphics.

\documentclass{article}
\usepackage{pdfpages}
\newlength{\tempwidth}
\begin{document}
\settowidth{\tempwidth}{\includegraphics[page=1]{lipsum.pdf}}
\includepdf[fitpaper,pages=1,trim={0 0 {.5\tempwidth} 0},clip]{lipsum.pdf} % ***
\end{document}

full page

  • This is a great solution to my actual problem, thank you! I still don't understand what happens to the pages option - presumably adjustbox fails to pass it down to the base \includegraphics? But the package uses a lot of key code that I don't understand. – Alex Watson Aug 27 '14 at 20:52
2

The page key was unfortunately not supported by adjustbox till v1.1 from 2018/04/08. If you update to this version or a later one your code should start working.

Also trim={0 0 {.5\width} 0},clip can be shorten to Clip={0 0 {.5\width} 0} (note the uppercase 'C') if adjustbox is used with export or Export option.

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.