# Include a document into another document with clipping

I want to include a document into another one. The document, which should be included, exists as pdf and tex file. The document which I want to include is about 30 pages. I want to include the document in the manner described below.

The included document should have a border around. Furthermore around the text of the sub document is a lot of white space due to the documentclass article. This white can be deleted. So that the text begins near the border(see screenshot). Because the sub document has a lot of graphics and tikz drawings it isn't that simple just making the size/format of the document smaller. Because this would have an effect on the graphics which would be too small.

An short extract of the header of my Main Document:

\documentclass[paper=A4,abstracton,twoside,openright,11pt,headsepline,BCOR=1cm,DIV=10,utf8]{scrreprt}
\begin{document}

\appendix
%here should be my included document

\end{document}


An example of my Sub Document:

\documentclass[11pt]{article}
\usepackage{geometry}
%i have done this, to clip the white space around
\geometry{a4paper, top=10mm, left=10mm, right=10mm, bottom=10mm,headsep=10mm, footskip=5mm}
%...
\begin{document}
example text example text example text example text example text example text  example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text example text
\end{document}

• \\includegraphics[]{} or \includepdf[]{} from graphicx or pdfpages. Both offer cropping and you can add frames as you wish. pdfpages provides an option for this, I think. – cfr Nov 20 '15 at 14:12
• – cfr Nov 20 '15 at 14:18
• I included my pdf with \includepdf[pages={1-},frame,scale=0.8]{sub/subdocument.pdf}. I deleted the white space around the subdocument with the geometry package. But the pagenumber from the main document (see screenshot above) is still missing. How can i achieve this? – d4rty Nov 20 '15 at 14:52
• Also the \includepdf.. gives me not the option to customize the border/frame. Is there a better solution? – d4rty Nov 20 '15 at 14:59
• Please edit your question to include a minimal working example (MWE). That makes it much easier to anyone who would like to help you to determine what happened to the page number. – jarauh Nov 20 '15 at 15:44

I included my pdf with \includepdf[pages={1-},frame,scale=0.8]{sub/subdocument.pdf}. I deleted the white space around the subdocument with the geometry package. But the pagenumber from the main document (see screenshot above) is still missing. How can i achieve this?

The problem with main document page numbers is due to pdfpage's option pagecommand which by default is pagecommand={\thispagestyle{empty}}.

Forcing a new pagecommand will solve the problem:

\documentclass[paper=A4,abstracton,twoside,openright,11pt,headsepline,BCOR=1cm,DIV=10,utf8]{scrreprt}
\usepackage{pdfpages}
\begin{document}

\appendix
%here should be my included document
\includepdf[pages={1-},frame,scale=0.8,
pagecommand={}]%  <---------- doesn't change pagestyle
{arsclassica/ArsClassica.pdf}
\end{document}


In case someone wants a pure TikZ framework, here is it.
(notice that even clipping is done in TikZ.)

\documentclass{scrreprt}
\usepackage{tikz}
\usetikzlibrary{calc,spy}
\begin{document}

\appendix
\chapter{Special Package}

\pgfdeclarelayer{back}
\pgfdeclarelayer{fore}
\pgfsetlayers{back,main,fore}
\tikzset{
on layer/.code={\pgfonlayer{#1}\begingroup\aftergroup\endpgfonlayer\aftergroup\endgroup}
}
\clearpage
\tikz[remember picture,overlay]{
\scoped\clip[rounded corners=20,postaction={on layer=fore,line width=10,draw}]($(current page.south west)+(2,7)$)rectangle($(current page.north east)+(-2,-7)$)(current page)node{\includegraphics[page=1]{tikz-3dplot_documentation}};
\draw[<-,red,line width=2,bend right](current page)++(4,2)to++(2,10)node[above]{\Huge Notice This};
}
\clearpage
\tikz[remember picture,overlay,spy using outlines={circle,magnification=4,size=4cm,connect spies}]{
\scoped\clip[rounded corners=20,postaction={on layer=fore,line width=10,draw}]($(current page.south west)+(2,7)$)rectangle($(current page.north east)+(-2,-7)$)(current page)node{\includegraphics[page=2]{tikz-3dplot_documentation}};
\spy[red]on(5,-15)in node at(4,-23);
}
\clearpage
\tikz[remember picture,overlay]{
\scoped\clip[rounded corners=20,postaction={on layer=fore,line width=10,draw}]($(current page.south west)+(2,7)$)rectangle($(current page.north east)+(-2,-7)$)(current page)node{\includegraphics[page=3]{tikz-3dplot_documentation}};
\fill($(current page)+(-6,-2.3)$)rectangle node[white]{\Huge Censored}($(current page)+(6,-.6)$);
}
\clearpage
\tikz[remember picture,overlay]
{
\scoped\clip[rounded corners=20,postaction={on layer=fore,line width=10,draw}]($(current page.south west)+(2,7)$)rectangle($(current page.north east)+(-2,-7)$)(current page)node{\includegraphics[page=4]{tikz-3dplot_documentation}};
\fill[on layer=back,yellow]($(current page)+(-6.1,.8)$)rectangle($(current page)+(6,-1.7)$)node[below left,olive]{\Huge Important};
}
\clearpage
\tikz[remember picture,overlay]
{
\clip[draw](current page)circle(5);
\scoped\clip[rounded corners=20,postaction={on layer=fore,line width=10,draw}]($(current page.south west)+(2,7)$)rectangle($(current page.north east)+(-2,-7)$)(current page)node{\includegraphics[page=5]{tikz-3dplot_documentation}};
}
\clearpage
\tikz[remember picture,overlay]
{
\scoped\clip[rounded corners=20,postaction={on layer=fore,line width=10,draw}]($(current page.south west)+(2,7)$)rectangle($(current page.north east)+(-2,-7)$)(current page)node{};
}
\vfill

\end{document}


The document you want to include is not two-sided. Therefore, you could perform the same per-page clip to trim off the excess whitespace (margins), and include each page using a straight-forward \includegraphics:

\documentclass{article}
\usepackage{multido,graphicx,lipsum}
\begin{document}

\section{Introduction}
\lipsum[1-10]

\section{Appendix}

% https://tex.stackexchange.com/q/198091/5764
\pdfximage{lipsum50.pdf}% Contains 50 pages of \lipsum text
\multido{\i=1+1}{\the\pdflastximagepages}{%
\fbox{\includegraphics[scale=.5,page=\i,viewport=50 40 565 750,clip]{lipsum50}}%
\clearpage}

\end{document}


The principle of this solution is to count the number of pages in the document to be included, and then iterate over each page using a framed \includegraphics. The viewport is set to only include the relevant part of each page, clipping the margins. You may have to play with the viewport values (they're in bp).

• what is \lipsum[1-10] doing? – d4rty Nov 23 '15 at 10:34
• @d4rty: Just provides you with some document content (in the form of "Lorem ipsum...") prior to the included pages for a frame of reference. – Werner Nov 23 '15 at 13:17