# Include trimmed multipage PDF in XeTeX

I have a multipage PDF manuscript (for example, my_PDF.pdf) that I would like to include in a new document. I would also like to trim/clip off the header and footer from each page of this included pdf.

In the past, with regular LaTeX, I have done this very simply with something like

\documentclass[letterpaper]{article}
\usepackage{pdfpages}

\begin{document}
\includepdf[pages={1,2},trim=0.45in 0.625in 0.45in 0.625in, offset=0.25in 0in, width=6in, clip=true, pagecommand={}]{my_PDF}
\end{document}


as described at http://en.wikibooks.org/wiki/LaTeX/Importing_Graphics.

However, this time I need to do it in XeTeX for Unicode support, and the above method doesn't work because clipping isn't supported yet in XeTeX. I've managed to come very close by using the nice adjustbox package, which lets you (almost) transparently redefine the \includegraphics macro in a way that supports clipping:

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\setlength{\pdfpagewidth}{8.5in} % Something wrong with my compiler setup
\setlength{\pdfpageheight}{11in}

\documentclass[letterpaper]{article}
\usepackage{pdfpages}

\begin{document}
\includepdf[pages={1,2},trim=0.45in 0.625in 0.45in 0.625in, offset=0.25in 0in, width=6in, clip=true, pagecommand={}]{my_PDF}
\end{document}


But now I'm stuck again because it doesn't seem the \adjustbox way can select different pages in the multipage PDF (i.e. this second code example repeatedly inserts the same properly-trimmed first page).

Is there a way to make this work? Maybe I'm missing a way to select the pages? Or somehow use the original way to insert the pages, in combination with some sort of pagecommand={\adjustbox{...}} key to the \includepdf macro? (I tried this too, but I am a relative novice and couldn't get it going) Perhaps there's a totally different method that I'm missing. Basically, I just want to be able to insert a cropped/trimmed multipage PDF document inside an XeTeX document.

-
Is it appropriate for you to consider lualatex? As far as I recall, clipping should work there (just as for pdflatex) because it’s based on PDFTeX whereas xelatex creates the PDF from an intermediate “enhanced DVI” format. –  ilpssun Mar 16 '12 at 10:25
Is it an option for you to generate the cropped pdf first using pdflatex and pdfpages and subsequently include the cropped pages in the XeLaTeX document? –  Martin Heller Mar 28 '12 at 21:44
@MartinHeller Thanks! This is close to the route I took. I ended up using pdfcrop2, since I didn't have that many pdfs to insert. I'm still curious about if/when there will be a way to solve this without the extra outside step. –  John Colby Mar 28 '12 at 23:22
@ilpssun Thanks! This sounds great. I didn't know much about lualatex before, but from reading a bit it's sounding like it might eventually surpass xelatex for typical users like me. I will definitely give it a shot and see if it goes smoothly or if I bump into any other issues... –  John Colby Mar 28 '12 at 23:27
@MartinHeller Would you like to make your comment into an answer? You may also point out that clipping support in XeTeX is work in progress. –  egreg Jul 4 '12 at 9:17

One option would be to generate a cropped PDF using pdfLaTeX and the pdfpages package, and then to use this PDF in a XeLaTeX run. You might also consider LuaLaTeX in place of XeLaTeX, depending on your exact requirements. Clipping for XeLaTeX is now sorted out for adjustbox, so you may wish to revisit this approach.