In order to crop a given PDF page in a given PDF file, what must one do? My preference is to guess geometric borders as little as possible along with using as little code as possible. Could someone help me with this?
Feb 8 in Others 334 views

## 1 answer to this question.

To answer your question, you could use various options, most of which should help you. You could crop the PDF page by point-and-click by using a GUI at the front-end which includes the functions:- pdf-quench, krop, briss and PDF scissors. You can also crop by using the given command line:- pdfcrop command which is provided by texlive-extra-utils by using various of the arguments like: pdfcrop --margins '-30 -30 -250 -150' --clip input.pdf output.pdf in the sequence of -left -top -right -bottom format. Ghostscript and the Convert -crop command (which is specifically provided by imagemagick) can also be used to crop by using the command line. However, if you want to write your own script and then initiate the cropping process, you can use Python and LaTeX, both of which is code is mentioned below:-

Python:-

#!/usr/bin/python
#

from pyPdf import PdfFileWriter, PdfFileReader

with open("in.pdf", "rb") as in_f:
output = PdfFileWriter()

numPages = input1.getNumPages()
print "document has %s pages." % numPages

for i in range(numPages):
page = input1.getPage(i)
print page.mediaBox.getUpperRight_x(),
page.mediaBox.getUpperRight_y()
page.trimBox.lowerLeft = (25, 25)
page.trimBox.upperRight = (225, 225)
page.cropBox.lowerLeft = (50, 50)
page.cropBox.upperRight = (200, 200)

with open("out.pdf", "wb") as out_f:
output.write(out_f)

LaTeX:- You can crop or trim a PDF when including it by using the trim=left botm right top.

\begin{figure}[htbp]
\centering
\includegraphics[clip, trim=0.5cm 11cm 0.5cm 11cm, width=1.00\textwidth]{gfx/BI-yourfile.pdf}
\caption{Title}
\label{fig:somthing}
\end{figure}

However, please note that while figuring out how far to trim could take a bit of time and to ensure a quicker process, you can draw a box around the image by using the given line:-

\fbox{\includegraphics[trim=0.5cm 11cm 0.5cm 11cm]{gfx/BI-yourfile.pdf}}

answered Feb 8 by
• 9,670 points

## how can I deploy a test in pytest framework to airflow using DAG?

I have established an automative testing framework ...READ MORE

## How can I open a URL in Android's web browser from my application?

ry this: Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri ...READ MORE

## How can I convert excel to PDF by Libreoffice and keep all format from excel file?

"Times New Roman" typeface does not have ...READ MORE

## Reading PDF file from Azure blob storage

For pdf reading and manipulating Itextsharp libraby is fine. For ...READ MORE

## How to view pdf stored in S3 using Angular 5

You can refer to this blog to ...READ MORE

## argparse argument order

Using Pisa will serve your needs.. READ MORE

+1 vote

## Looping through PDF files to extract specific data using Uipath

Hi Rashi, you can access all the ...READ MORE