OliverMarshall.net

How to print PDF files and automatically include a filename

I was asked how to print PDF files and automatically include a filename on the print out. This was for a team of users whose technical diagrams were meant to include the filename of the file but, inevitably, this was missed out. In many applications you can automate this process, include variables in the footer or header, but in this case the users used a variety of tools and really the only common factor was that they delivered the final versions in PDF format.

The solution had to be pretty straightforward, ideally with someone being able to right click the file and print it with a filename stamped on the print out.

The solution is a bit long-winded but it works well and, once done, should just keep on ticking. I’m assuming that all the machines are Windows 10 64bit.

  1. Install Irfanview 64-bit from here and install it. Irfanview is a superb opensource image viewer with great batch file and command line features.
  2. Install the Irfanview 64-bit plugin pack from here. This will add support for viewing PDFs (as well as loads of other file types).
  3. Open Irfanview 64-bit and from there open a PDF file. You may have to change the filename to *.PDF in order to show PDF files.
  4. Now print the file by clicking File > Print from the menu bar. We’ll be setting the Footer information to include the filename variable ($F). Be sure to click the SAVE button (highlighted).
  5. Cancel that box and close Irfanview.
  6. Now that the printing aspect is configured we need to add a right click menu. I created a custom context menu entry to send the file to Irfanview and order it to print using the default printer. Download the REG file here. Expand the zip file and double click the reg file you find there. This will add it to your registry. You may need to reboot afterwards but it should just work.
  7. You should now see a new right click menu when right clicking PDF files.

How does it work?

Irfanview view takes care of adding the filename as a footer to the print out. We’re focusing on a PDF here but it could be any file type that Irfanview supports. As long as you save the printer settings in the printer dialogue then that footer will be included in anything that’s printed out.

The context menu is handled by a registry entry that’s kept in the .reg file. Double-clicking the .reg file imports it. The .reg file itself looks like this;

You can see that it assumes the location of Irfanview is “C:\Program Files\IrfanView\i_view64.exe” which is fine for any x64 version of Windows. If you wanted to change this to work with JPG files then you could just edit the .reg file in Notepad and replace .PDF with .JPG, save, and re-import the file.

 

 

Exit mobile version