A new command that works like \includegraphics, but crops the pdf image:
\newcommand{\includeCroppedPdf}[2][]{%
\immediate\write18{pdfcrop #2}%
\includegraphics[#1]{#2-crop}}
Remember: \write18 needs to be enabled. For most TeX distros set the --shell-escape flag when running latex/pdflatex etc.
Example
\documentclass{article}
\usepackage{graphicx}
\newcommand{\includeCroppedPdf}[2][]{%
\immediate\write18{pdfcrop #2}%
\includegraphics[#1]{#2-crop}}
\begin{document}
\includeCroppedPdf[width=\textwidth]{test}
\end{document}
Avoid cropping on every compile
To avoid cropping on every document compilation, you could check if the cropped file already exists. (some checksum would be better)
\documentclass{article}
\usepackage{graphicx}
\newcommand{\includeCroppedPdf}[2][]{%
\IfFileExists{./#2-crop.pdf}{}{%
\immediate\write18{pdfcrop #2 #2-crop.pdf}}%
\includegraphics[#1]{#2-crop.pdf}}
\begin{document}
\includeCroppedPdf[width=\textwidth]{test}
\end{document}
MD5 Checksum Example
The Idea is to save the MD5 of the image and compare it on the next run. This requires the \pdf@filemdfivesum macro (only works with PDFLaTeX or LuaLaTeX). For XeLaTeX You could use \write18 with md5sum utility or do a file diff.
\documentclass{article}
\usepackage{graphicx}
\usepackage{etoolbox}
\makeatletter
\newcommand{\includeCroppedPdf}[2][]{\begingroup%
\edef\temp@mdfivesum{\pdf@filemdfivesum{#2.pdf}}%
\ifcsstrequal{#2mdfivesum}{temp@mdfivesum}{}{%
%file changed
\immediate\write18{pdfcrop #2 #2-crop.pdf}}%
\immediate\write\@auxout{\string\expandafter\string\gdef\string\csname\space #2mdfivesum\string\endcsname{\temp@mdfivesum}}%
\includegraphics[#1]{#2-crop.pdf}\endgroup}
\makeatother
\begin{document}
\includeCroppedPdf[width=\textwidth]{abc}
\end{document}
pdfcropfrom your TeX document. I don't know whether the cropping would be synchronous (good) or asynchronous (bad). – Ethan Bolker Dec 29 '13 at 14:54pdfcropon all the files first, e.g. with a for loop? Which operating system do you use? – Torbjørn T. Dec 29 '13 at 15:35\immediate\write18{pdfcrop charge_distribution.pdf tmp.pdf} \includegraphics[width=\textwidth]{tmp.pdf}Now I would like to try to create some kind of macro (or some similar structure, I am not that familiar with LaTeX yet) that would enable me to do that in a quicker way – tales Dec 29 '13 at 15:44for f in *.pdf do ; pdfcrop $f ; doneis quite quick, isn't it?) Sure, it's a perfectly reasonable request. You may want some way of turning off the cropping, or checking for a cropped file, otherwise the cropping will be done every time you compile your document. That is partly the reason I would do it outside the LaTeX file, it's something you need to do just once. – Torbjørn T. Dec 29 '13 at 19:34