I want to run a postprocessing script on my pdf. For integration with my editor it should be executed at the end of the pdflatex run, automatically -- ideally without having to change the compilation command in order not to break the behaviour for other documents.
I thought that I could do this with the atveryend package, using
%% minimal example file where \write18 is used for cropping.
\documentclass[]{article}
\title{}
\author{}
\usepackage{lipsum}
\usepackage{atveryend}
\AtVeryVeryEnd{
\message{^^J=== STARTING POSTPROCESSING ===^^J}
\immediate\write18{pdfcrop \jobname.pdf \jobname.pdf}
}
\begin{document}
\maketitle
\begin{abstract}
\lipsum[1]
\end{abstract}
\section{A section}
\lipsum[2-3]
\end{document}
But this fails. One can see from the log entries that even \AtVeryVeryEnd is executed a while before Output written on document.pdf is printed, i.e. the PDF file's handle is still open at that time. I can't say how this would behave on unix (where exclusive file locks are less common), but on my Windows machine it makes pdfcrop crash.
Is there some method to execute the command at the "VeryVeryVery" end of the pdflatex run, after the PDF file has been closed?
\endhas been executed, so nothing can be read from the input at that time. What aboutpdflatex file && pdfcrop file? – egreg Jul 16 '15 at 09:32