Do you have a pile of old print-outs of PDF documents on your desk that correspond to different versions of the same file, but you can't see which printout corresponds to which version? And the file in question sits in a git repository?
Well, your prayers shall be heard. Here's the answer to that mess: Just watermark each PDF before you print it with the git commit id. You can find out the current git commit id with git describe --always.
How to get that onto you PDF? Either use a pen or pdflatex with the pdfinput and tikz packages. For those of us who don't like to use pens the script below automates that task. Just say (assuming you have named the script commitid and put it to some place in your PATH)
commitid filename.pdfand the file will be watermarked with the current git commit id (well, something like that).
Enjoy!
#!/bin/bash # Time-stamp: <2011-10-12 13:45:23 rueffer> # (c) Bjoern Rueffer 2011 # check parameters for validity: if [ ! -f "$1" -o $# -ne 1 ]; then cat <<EOF Usage: $0 <pdf file> This command will take a pdf file located in a git repository and watermark it with the current commit id. (c) Bjoern Rueffer 2011 EOF exit 1 elif ! git describe --always >/dev/null 2>&1; then cat <<EOF Error: This command must be invoked in a git repository! (Otherwise I cannot know which commit ID to use.) EOF exit 1 elif !(echo "$1" | grep -i 'PDF$' >/dev/null 2>&1); then cat <<EOF Error: The file appears not to be PDF. I can only process PDF files. EOF exit 1 fi echo -n Processing "$1" with git commit ID `git describe --always` ... COMMITID=`git describe --always` cp "$1" /tmp/pdf_to_stamp.pdf cat >/tmp/commitid.tex <<EOF \documentclass{scrlttr2} \usepackage{pdfpages,pgf,tikz} \pagestyle{empty} \begin{document} \includepdf[fitpaper,pages=-,% picturecommand={},% pagecommand={% \begin{tikzpicture}[remember picture, overlay] \node [xshift=1cm,yshift=-1cm,below right, fill=yellow!50, rounded corners, opacity=.5] at (current page.north west) {% commit id: $COMMITID \qquad \today \qquad p.\thepage }; \end{tikzpicture}% }% ]{/tmp/pdf_to_stamp.pdf} \end{document} EOF (cd /tmp; pdflatex commitid && pdflatex commitid) >/dev/null 2>&1 cp /tmp/commitid.pdf "$1" rm /tmp/commitid* echo \ done.
1 comments:
Comments are moderated to prevent abuse and may not be made public immediately.