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 in Others by Rahul
• 8,980 points
15 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 by Soham
• 8,730 points

Related Questions In Others

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
25 views
0 votes
1 answer

How do I start studying Node.JS to create a restful API?

Node.js is an open source server environment ...READ MORE

answered Jun 11, 2019 in Others by ArchanaNagur
• 2,340 points
416 views
0 votes
0 answers

How can i solve NoClassdeffoundError on my mobile?

Oct 15, 2019 in Others by SolomonTS
• 120 points
165 views
0 votes
1 answer

How do I get a cheap domain name? - web hosting

Many web hosting companies like amazon's lighsail ...READ MORE

answered Oct 28, 2019 in Others by Yesha
307 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,060 points
4,937 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
311 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
5,847 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 in Others by Soham
• 8,730 points
13 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 in Others by Soham
• 8,730 points
62 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP