Add filename in a pdf document

I have hundreds of pdf documents to print. I would like to add the filename of the document on the top. I do not care this is done inside the document or if it is just added when printing. I did find how to add page numbers...however I am unable to translate this solution to my needs.

Any suggestions would be highly appreciated - and they would save my day.


If you use a script to print all the PDF files in a directory you can do this:

#!/bin/bash
for f in *.pdf
do
echo "$f" | lpr
lp -o job-sheets=none "$f"
done

It isn't pretty, but it will begin each pdf file with a page containing the filename. This doesn't require you to troubleshoot what's going wrong with groff but as I said, it's ugly. You could experiment with adding newlines and spaces to push the filename into the center of the first page, and if your printer supports it, even use ESC/P codes to bold the print.

I still think the groff solution mentioned by Graham in the comments is superior but this is an alternate solution, free of typos.

Note: Requires a printer set to default. I used the System-wide default for testing.