\documentclass{article}
\usepackage{graphicx}
\title{Auto remove PDF blank margin when includegraphics in Overleaf}
\author{}
\begin{document}
\maketitle
Here we have one graphic to include \textit{example1.pdf}.
\fbox{\includegraphics[width=.9\linewidth]{example1.pdf}}
We can see \textit{example1.pdf} has blank margin. We make a copy of \textit{example1.pdf} and rename it as \textit{example2.crop} and include it.
\fbox{\includegraphics[width=.9\linewidth]{example2.pdf}}
We can see that the white margin is cropped automatically.
The main trick we've done is that we add custom file dependency \textit{.crop} to \textit{.pdf}, and handle it with \textbf{pdfcrop} in the \textit{.latexmkrc} file.
If you want to put the figures in a sub-directory, you have to add it to \textit{TEXINPUTS} environment variable in the \textit{.latexmkrc} file.
The cropped pdf graphics can also be downloaded from \textbf{Logs and output files $>>$ Other logs and files} if needed.
\end{document}