How can I easily crop a PDF page

0 votes
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, 2022 in Others by Rahul
• 9,670 points
514 views

1 answer to this question.

0 votes

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: 
      input1 = PdfFileReader(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) 
output.addPage(page) 

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, 2022 by Soham
• 9,700 points

Related Questions In Others

0 votes
1 answer

How can I convert a Word document to PDF?

This is a difficult task, made even ...READ MORE

answered Oct 31, 2022 in Others by narikkadan
• 53,520 points
173 views
0 votes
0 answers

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

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

Oct 4, 2021 in Others by Yuan
• 120 points
285 views
0 votes
1 answer

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

answered Jun 14, 2022 in Others by polo
• 1,480 points
1,660 views
0 votes
1 answer

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

answered Oct 3, 2022 in Others by narikkadan
• 53,520 points
466 views
0 votes
2 answers

Reading PDF file from Azure blob storage

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

answered Aug 17, 2018 in Azure by Priyaj
• 58,100 points
5,793 views
0 votes
1 answer
0 votes
2 answers

argparse argument order

Using Pisa will serve your needs.. READ MORE

answered Feb 28, 2019 in Python by Pratosh kumar
419 views
+1 vote
2 answers

Looping through PDF files to extract specific data using Uipath

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

answered Mar 5, 2019 in RPA by Anvi
• 14,170 points
6,381 views
0 votes
1 answer

How to take a screenshot of a current Activity and then share it?

For me, I captured and then shared ...READ MORE

answered Feb 8, 2022 in Others by Soham
• 9,700 points
100 views
0 votes
1 answer

How to delete duplicate rows in SQL Server?

To answer your query, note that CTEs ...READ MORE

answered Feb 10, 2022 in Others by Soham
• 9,700 points
372 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP