Print PDF file with file path in footer


I would like to print a PDF on windows, but want to print the path of the PDF file in the footer of the printed document (like I am able to do in Word).

We are using either Adobe Reader or Foxit Reader.

Do you know any way how to achieve this ?

Best Answer

First off: some printer drivers would allow you to define a "watermark" for each page printed. You may be able to abuse that feature in order to do what you want. However, to the best of my knowledge, Acrobat Reader does not include such a feature (though you may be able to (ab)use the builtin JavaScript support inside Acrobat to achieve something like what you want...

OK then. Let me also give it a shot. Since we are here on (and not, I'll do without a programming language, and use just (batch) scripting instead.

First step: Use Ghostscript to create a PDF footer page showing the 'footer' string with a path

We'll use a relatively simple Ghostscript command for that. The command takes a short PostScript snippet as commandline input (-c "...") and outputs the PDF as 'myfooter.pdf'. We'll use letter as the media size (replace with a4 or whatever you need). Here goes:
(I'm assuming we are on Windows. Should one of the readers be on Linux, use gs instead of gswin32c.exe.)

gswin32c.exe ^
 -o myfooter.pdf ^
 -sDEVICE=pdfwrite ^
 -sPAPERSIZE=letter ^
 -c "72 12 moveto /Helvetica findfont 9 scalefont setfont (File: d:\\c\\b\\a.pdf) show"

Now we have a PDF page that contains the footer only, with the rest of the canvas without any content. You can open it in a viewer and see that the string starts at 72 PostScript points (72 pt == 1 inch) to the left of the lower left corner, and 12 points to the top.

Second step: Use the PDF ToolKit to overlay the footer page with your original PDF

We'll use the PDF ToolKit's pdftk.exe command now. This commandline utility can do a lot of things to PDFs. The feature we need here: overlay pages from two different PDF documents over each other in order to provide a 'stamp' or a 'background' to the original file. Here goes:
(Should a reader be on Linux, use pdftk instead of pdftk.exe.)

pdftk.exe ^
  d:\c\b\a.pdf ^
  stamp myfooter.pdf ^
  output d:\c\b\result-with-footer-a.pdf

(BTW, pdftk is also derived from the iText libarary, the one the other answer refers to.)

Third step: Create a batch script that makes both previous steps happen automatically

This is left for your exercising pleasures... ;-)

You may want to rotate the string by 90 degree, so it reads vertically on the left page border. For this case modify the Ghostscript command like this: gswin32c.exe -sDEVICE=pdfwrite -o myfooter.pdf -dAutoRotatePages=/None -c "12 72 moveto /Helvetica findfont 9 scalefont setfont 90 rotate (File: d:\\c\\b\\a.pdf) show showpage".