# How to crop a PDF using LaTeX

Submitted by Nicola Rainiero on 2012-07-06 (last updated on 2015-03-29)

Very often you want to read comfortably on screen or on eBook reader, the PDFs created for printing: two side or slides of presentations (2 or more slides per page), without zooming or scrolling from side to side. After several fruitless searching I have found a great solution: LaTeX. With the help of 2 different types of PDFs, I show you how to automatically crop them.

Speaking of LaTeX to friends or colleagues, I make them smile and sometimes I obtain malicious comments, but don't worry: pronounced /ˈleɪtɛk/, /ˈleɪtɛx/, /ˈlɑːtɛx/, or /ˈlɑːtɛk/, this is a document markup language and document preparation system for the TeX typesetting program, as reported on Wikipedia. I suggest you an excellent introductory guide: L'arte di scrivere con LaTeX written by Lorenzo Pantieri and Tommaso Gordini.

Well, after this necessary introduction, I found on the Net the solution to my necessities: the two2one.tex file written by J.S. Milne, at this link. At first I did more attempts to get acceptable results, I made some mistakes in taking the measures of the pages and many times new edges appeared in the final PDF (when selected areas don't respect the A4 size proportion). Even for the last problem, I found solution by reading this article: LaTeX - how do I force PDF page height/width?.

## The requirements

LaTeX with the following packages: geometry to define the new page size, pdfpages to include PDF pages in TeX documents and ifthen for conditional commands. Or using WriteLatex online without installing anything.

## Typical procedure in 4 steps

1. You have to know:
• Page size in points (pt width x pt height), page layout (portrait or landscape) and exact number of pages to cut out;
• The two coordinates measured in points that contain the cutting selection: x0,y0 at the bottom left side (rounding-down) e x1,y1 at the top right side(rounding-up);
2. If you have more selections, you must use the bigger size cutting in order to having an uniform PDF, i.e. you subtract the coordinates (x1-x0=width, y1-y0=height) for every cuttings and will use the bigger dimensions to define new page size;
3. Rewrite the measures in a LaTeX file, the layout orientation and total number of pages;
4. Run pdflatex.

## Example 1: two-side document

This is a PDF with two different margins: the first for the right page (odd pages) and second for the left one (even pages).

 Find size of the page (595x841 pt) Highlight the interest areas Find the coordinates (x,y), remember that (0,0) is in the bottom left of the page

Using these data, you type the following LateX file (da_two_side.tex):

%%Original version by J.S.Milne 25.09.05 (two2one.tex - http://www.jmilne.org/math/Books/scan.html)
%%Updated by Nicola Rainiero (http://rainnic.altervista.org/it/tag/latex)
%%Correct this file for the number of pages in your document
%%Correct this file for the size of your document in postscript points
%%To do this, you need to find the size of your input document in points (Inkscape, Gimp or PDF Reader)
%%Run pdflatex on this file: pdflatex "name of this file"

% letterpaper, landscape or portrait
\documentclass[portrait]{minimal}
%%force the final dimension of PDF, put the maximum difference among the coordinates of the cropped areas
%%(x direction: width, y direction: height)
\usepackage[paperwidth=383pt,paperheight=696pt]{geometry}
\usepackage{pdfpages}
\usepackage{ifthen}

\newcounter{pg} %counter of pages
\begin{document}
\setcounter{pg}{1} %fix the first page
%% my pdf file has 10 pages
%% my pdf file has size 595 x 841 points (width X height)
\whiledo{\value{pg}<10}{% default pages + 1, pages +0 if there are two increments of pg
%%x0,y0 at the bottom left -- x1,y1 at the top right of the selection
\includepdf[pages=\thepg,viewport=80 87 463 783]{two_side.pdf} %pages on the right side, (odd pages)
\includepdf[pages=\thepg,viewport=128 87 511 783]{two_side.pdf} %pages on the left side, (even pages)
}%

\end{document}



Summary:

 input file output file two_side.pdf da_two_side.pdf

## Example 2: landscape presentations with 4 slides every page

I chose this type, to highlight the versatility and simplicity of this method.

 Find size of the page (841x594 pt) Highlight the interest areas Find the coordinates (x,y)

Using these data, you type the following LateX file (da_4_slide_orizzontali.tex):

%%Original version by J.S.Milne 25.09.05 (two2one.tex - http://www.jmilne.org/math/Books/scan.html)
%%Updated by Nicola Rainiero (http://rainnic.altervista.org/it/tag/latex)
%%Correct this file for the number of pages in your document
%%Correct this file for the size of your document in postscript points
%%To do this, you need to find the size of your input document in points (Inkscape, Gimp or PDF Reader)
%%Run pdflatex on this file: pdflatex "name of this file"

%%letterpaper, landscape or portrait
\documentclass[landscape]{minimal}
%%force the final dimension of PDF, put the maximum difference among the coordinates of the cropped areas
%%(x direction: width, y direction: height)
\usepackage[paperwidth=285pt,paperheight=199pt]{geometry}
\usepackage{pdfpages}
\usepackage{ifthen}

\newcounter{pg} %counter of pages
\begin{document}
\setcounter{pg}{1} %fix the first page
%% my pdf file has 1 page
%% my pdf file has size 841 x 594 points
\whiledo{\value{pg}<2}{% default pages + 1, pages +0 if there are two increments of pg
%%x0,y0 at the bottom left -- x1,y1 at the top right of the selection
\includepdf[pages=\thepg,viewport=68 347 353 546]{4_slide_orizzontali.pdf} %first slide
\includepdf[pages=\thepg,viewport=488 347 773 546]{4_slide_orizzontali.pdf} %second slide
\includepdf[pages=\thepg,viewport=68 49 353 248]{4_slide_orizzontali.pdf} %third slide
\includepdf[pages=\thepg,viewport=488 49 773 248]{4_slide_orizzontali.pdf} %fourth slide
}
\end{document}


Summary:

 input file output file 4_slide_orizzontali.pdf da_4_slide_orizzontali.pdf

All PDF of this guide and the corresponding TEX files have been compressed here: Esempi_su_come_ritagliare_un_PDF.zip

## Related Content:

### Nicola Rainiero

A civil geotechnical engineer with the ambition to facilitate own work with free software for a knowledge and collective sharing. Also, I deal with green energy and in particular shallow geothermal energy. I have always been involved in web design and 3D modelling.