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}}