2014/09/13

Editing PDFs

After trying several methods for editing .pdf files, including pdfedit and xournal, I have come to the conclusion that the best method is by combining latex with tikz.

The procedure is this:
for a multipage pdf document, burst it with pdftk
pdftk file.pdf burst
Each page now gets included in a tex document
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics{file-page1.pdf}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\draw[step=0.05,red,thin,dotted] (0,0) grid (1,1);
\end{scope};
\end{tikzpicture}
\end{document} 
So, the page to be edited serves as an image, and whatever needs to be put on it can be done using standard tikz commands, which can be used for drawing, writing, highlighting, underlining, inserting images, etc.
The \draw...grid...; command helps in finding the coordinates where the edit should be done, and in the final run of the tex file should be deleted (or, commented with %). 

Finally, if need be, join pages with
pdftk file-page1.pdf file-page2.pdf cat output edited-file.pdf
This procedure involves a lot of guessing and it looks like a "brute force" approach, but it has produced the most satisfactory results so far.