Skip to main content
Working from scratch, following simplicity

How to crop and split a PDF online and in LaTeX but without using it

Every time I have to break iteratively a series of pages in a PDF document or just to crop the white pieces, I need to use different software and to find manually the coordinates of the sections to cut and then adjust my old LaTeX template. It is an extenuating procedure that requires the use of external software and some compilations to fix the cuts. So I have written a new template to overcome these issues, thanks to TikZ and Overleaf or a local TeX editor with live update. It follows a step by step guide with three useful examples in a practical slideshow.

In a previous article, How to crop a PDF using LaTeX, I have showed you how it’s powerful LaTeX to crop iteratively a PDF with the includepdf command, after obtaining the coordinates that contain one or more sections. Nevertheless there are two negative aspects:

  1. loss of time to find the coordinates and the dimension of the PDF pages with the necessity to use of another software (Inkscape, Gimp or PDF Reader for example);
  2. many process of compiling in the typical TeX editor to adjust the final cut sections.

So joining the powerful of Overleaf[fn]Overleaf is the new collaborative writing and publishing system developed by the team behind the popular writeLaTeX editor. Overleaf is designed to make the whole process of writing, editing and producing scientific papers much quicker for both authors and publishers. Overleaf: Real-time Collaborative Writing and Publishing Tools with Integrated PDF Preview. Here is my sign up link to Overleaf.[/fn], an online editor described in LaTeX online? WriteLaTeX of course!, and the drawing capability of TikZ, I have found a faster way to break PDF pages with and without using LaTeX, just changing a few line of code. Another good solution is to use a local editor with an integrated viewer and live update. Thanks to the Comparison of TeX editors, I discovered the existence of Gummi, a extremely simplified editor with a responsive live update.

With the new approach it is possible to work with an uploaded PDF file in two steps, still remaining inside the same editor and editing only a single part of the new template. In the first step, you highlight the region or the two regions of the typical page that you want to crop. In the second one, you finalize the output and if it satisfies you the job is finished, otherwise you have to return at the first step and fix the sizes again. Below I put a slideshow that shows you how it is simple to use thanks to the help of three examples.

Requirements

  • Out of the box in Overleaf, but a registration is needed in order to upload the PDF files and to edit my template.
  • If you want to use it in your computer: LaTeX, an editor and the following packages: mathptmx, moresize, comment, ifthen, pdfpages, tikz (almost standard in a typical LaTeX installation).

How it works

The entire process can be summarized with the infographic below and the following piece of code that you have to edit in order to get the final PDF.

Infographic: Crop and split a PDF online just editing a quick template in LaTeX

% <---------------------------- EDIT THIS AREA ONLY ----------------------------------->

% Default style and colour of the cutter
\tikzset{marker/.style={draw=blue,fill=blue, opacity=0.25}}

%% Every time one of the following must be activated and the others deactivated
%% \includecomment{...} --> means turn ON
%% \excludecomment{...} --> means turn OFF
\includecomment{first} 		% for discovering the dimension of the cuts
\excludecomment{second}		% for printing a cleaned and trimmed PDF
\excludecomment{third}		% for joining the pages of the II stage without white spaces
							% (save and use the new PDF before to do it)

%%
%% Define the file name and the dimension of your PDF
%% Put the size in mm
%% The typical size of an A4 document is 210x297 mm
\newcommand\units{mm}					% <--- set the units (default mm)
\newcommand\fileName{two_side.pdf}		% <--- the name of the PDF to process
\newcommand\width{420} 					% <--- the width size in mm of your PDF
\newcommand\height{297} 				% <--- the height size in mm of your PDF

%%
%% 							Do you want to crop the white spaces around the PDF?
%%
\newcommand\crop{1} 					% <-- "0" FALSE "1" TRUE
% If true put the dimension of the virtual rectangle that covers the pages
\newcommand\cutterW{150} 				% <--- the width size in mm of your cutter
\newcommand\cutterH{280} 				% <--- the height size in mm of your cutter

%%
%% 							Do you want to cut two sections per page?
%%
\newcommand\double{1} 					% <--- "0" FALSE "1" TRUE
%% If true put x_i, y_i the coordinates for moving the virtual rectangle in the page
%% the system start at the bottom left of the whole page
%% YOU CAN PUT ONLY INTEGER NUMBER
%% first rectangle in page (generally odd) or the only one
\newcommand\xOdd{30}					% <-- x_1
\newcommand\yOdd{3}						% <-- y_1
%% second rectangle in page (generally even)
\newcommand\xEven{242}					% <-- x_2
\newcommand\yEven{3}					% <-- x_2

%%
%% 							How many pages do you want to process?
%% default pages + 1, pages +0 if there are two page increment in the 2 step
\newcommand\numberPages{6} 				% <--- the numbers of pages
\newcommand\firstPage{1} 				% <--- fix the first page to start

% <---------------------------- EDIT THIS AREA ONLY  ----------------------------------->

Editing the area above, you control all the steps and the process to cut/split your original PDF and much more. You can find and download my template in Overleaf and GitHub:

Step by step guide


How to crop and split a PDF (in LaTeX, without using it) from Nicola Rainiero

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Sponsored Links
Pubblicità

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.