Skip to main content
Participant
August 30, 2006
Question

Print File Name with pdf Document

  • August 30, 2006
  • 93 replies
  • 245470 views
In order to have an audit trail / track a document, I want to print the file name as a header or footer when printing the documents. How can this be done?
This topic has been closed for replies.

93 replies

Participant
June 16, 2018

Thank you everybody for the great inputs.  I had a play of the javascript myself and got quite confused by the box coordinate.

1) Is x1,y1 the left lower hand corner of the box, and x2 y2 the right upper corner of the box?

2) The ToWidth business got me confused.  For example if I just want to put the filename, in font size 5, in the very top right hand upper corner of the page, how do I code the [x1, y1, x2, y2]  square box in the code please?

I would like to insert filename into the far right upper corner header of every document.  Document one may have 1000 x 1600 pixels per page; document two may be 600 x 800 pixels only; document three may be 1080 x 1024 per page for example.  How do I program the square box so it automatically calculates and fits the filename to the further top right hand corner every time please?

By the way there is a free software written by someone using C# you can download and do the job quickly without understanding anything.  It is here: by a guy called Saint Johnny.  His program is called: PDF Filename Labeller.

How To Batch PDF Filename, text date,time and Image Stamper (free) - YouTube

https://www.youtube.com/watch?annotation_id=annotation_3090625617&feature=iv&src_vid=7_2csux6A5M&v=HivH8cNQRDY

https://www.youtube.com/watch?annotation_id=annotation_3090625617&feature=iv&src_vid=7_2csux6A5M&v=HivH8cNQRDY

How To Batch PDF Filename, text date,time and Image Stamper (free) - YouTube

https://www.youtube.com/watch?annotation_id=annotation_3090625617&feature=iv&src_vid=7_2csux6A5M&v=HivH8cNQRDY

Commercial software like Nitro also lets you put variables into the header or footer.  However I do not know what the variable is called for filename and path.  Would anyone know please?

Enjoy.

Participant
December 29, 2015

I really don't understand all this Java Script stuff.  Why, oh why, is this not built into the basic product?  Seems like a NO BRAINER.  Absolutely should not take a programmer to do this simple task...

Just saying...

Inspiring
December 29, 2015

Acrobat is pretty well bloated so adding many features that are not commonly used would just add the bloat.

When PDfs were introduced, it was to be a type of universal cross platform document reader and only a few users has the tools to create PDFs, sort of like the original Mac and Lisa. In order to keep backward compatibility for all versions of PDFs Adobe has kept the original design and scripting, unlike MS Word that has more than once changed the VBA code.

Participant
September 10, 2015

The script to print filename in footer is great, but is there a way to print the filename ie in top or bottom center of the "selected view"?

Inspiring
December 29, 2015

One can use the add water mark from text to place the file name anywhere on the page. One could also add a field to any location on the page and set it's value to the file name.

gina_block
Participant
November 13, 2014

Perhaps someone has already suggested this, but if you are using Acrobat Pro (I'm on 11.0.0), go to Tools (now located on the upper right of the PDF) > Print Production > Add Printer Marks > Page Information. This will place the filename on the lower left of your PDF. You can also add trim, reg marks, and color bars, etc.

January 9, 2014

For googlers who find this thread down the road:

I made a tool to batch stamp PDF filenames.  You can get it here:

http://saintjohnny.com/pdffilenamelabeler

I've also added so that you can also stamp prefix/suffix before and after the filename, as well as stamp custom text ignoring filenames, and change the height of the stamp to go on the top of the page as a header if needed.  Since this isn't a true footer/header, it retains the information when combining PDFs later on which is a plus. 

Participating Frequently
August 5, 2011

Hi folks,

I used Reinhard's JavaScript file (http://www.refob.de/downloads/Acrobat/SetRemoveFooter.js) in Adobe Pro 9.0, and it worked like a charm.


But now, I want to do a batch of files, and I can't get it to work.  I saw on another post that I should just use the SetFooter code (bottom of this post).  So, I did the following:

1) Clicked Advanced > Document Processing > Batch Processing

2) Clicked Select Commands

3) Added "Execute JavaScript"

4) Added the SetFooter code

5) I kept the default settings and clicked OK.

When I selected the sequence, clicked Run Sequence, and selected a PDF, I got nothing. The sequence executed without any error messages, but when I opened the file, the footer was not at the bottom. I've tried several different PDFs and I get the same thing. None of them are secured. I even removed the the SetRemoveFooter.js file from the JavaScript folder, and it still didn't work.

Can someone tell me what I'm doing wrong?

Here is the code I used in the batch sequence:

function SetFooter(ARG)
{
var re = /.*\/|\.pdf$/ig;
var FileNM = this.path.replace(re,"")+".pdf";
var Path = this.path;
var AcDate = new Date();
var AcDateFormat = "yyyy/mmm/dd  HH:MM"
var Box2Width = 50
for (var p = 0; p < this.numPages; p++)
{
  var aRect = this.getPageBox("Crop",p);
  var TotWidth = aRect[2] - aRect[0]
  if (ARG<=3 || ARG==9)
   { var fd = this.addField("xftDate", "text", p, [30,15, TotWidth-30-30,30]);
      fd.value =  util.printd(AcDateFormat, AcDate) + "   (" + FileNM +")";
       fd.textSize=6; fd.readonly = true;
       if (ARG==1){ fd.alignment="left" };
       if (ARG==2){ fd.alignment="center" };
       if (ARG==3){ fd.alignment="right" };
    }
  if (ARG==4 || ARG==5 ||ARG==9)
   {  var bStart=(TotWidth/2)-(Box2Width/2)
       var bEnd=((TotWidth/2)+(Box2Width/2))
       if (ARG==5){var bStart=(TotWidth-Box2Width-30); var bEnd=(TotWidth-30);}
       var fp = this.addField(String("xftPage"+p+1), "text", p, [bStart,30,bEnd,15]);
       fp.value = "Page: " + String(p+1)+ "/" + this.numPages;
       fp.textSize=6;  fp.readonly = true;
       fp.alignment="center";
   }
}
}

ReinhardF
Participating Frequently
August 5, 2011

Hi,

first point: A function has to be called, like:

SetFooter(2);

second point: If you use may script you should avoid problems with redeclareing a function, so rename the function like:

SetFooterBatch(2);


function SetFooterBatch(ARG)

{

........

}

HTH, Reinhard

Participating Frequently
August 5, 2011

Hi Reinhard,

I forgot to mention that I'm almost completely ignorant when it comes to programming. I took a few variations of your instructions, and I'm still not getting this to work. Here they are:

1) Changed "function SetFooter(ARG)" to "function SetFooterBatch(ARG)"

2) Changed "function SetFooterBatch(ARG)" to "function SetFooterBatch(August)" and replaced all "ARG" in the code with "August". It didn't work, so I changed everything back to "ARG".

3) Added "SetFooterBatch(2);" to the top of my code.

4) Changed "SetFooterBatch(2);" to "SetFooterBatch(ARG);"

I'm sure the problem is obvious, but I'm very new to this. Any help will be appreciated. Thanks!

Participant
March 24, 2011

Hi, I am a novice at this, but I have the same requirement to print

filename and path on documents, particularly using the archive function.

Is there an easy way to do this in version Acrobat X pro?

Participant
September 6, 2010

How can this be done?

Contact support

http://www.xemtruyenhinh.info/

Inspiring
September 6, 2010

You can add the  water mark to show on print when you create the PDF assuming the  file will not be renamed. But you will need to add a 'Will Print" action to add the watermark or fill in a previously added field. If any users are using Reader you will not be able to add a watermark with JS.

Participant
October 5, 2009

Hi,

SetRemoveFooter.js works great but I actually only need the file path in the footer, so no date no page number.  And how can I get more than one line for the path since the paths for my files sometimes go beyound one line.

Also anyone know how to change the \192.168.1.1\Projets\test.pdf to M:\Projects\test.pdf??

Thanks for your help.

Participant
July 22, 2009

I'm sorry to echo a question that's been asked several times before, but would someone tell me how specifically to edit the provided javascript so that it creates a Header with the document name when printing, instead of a footer? Thank you very much for your help!

Inspiring
July 22, 2009

This is a very advanced script. To edit this script you will need to know about the coordinates system used in PDFs, how to obtain the page size, and how to compute the location at the top of the page.

See 'Automating Placement of Annotations' by Thom Parker for information on how to compute the quad locations for annotations or form fields.

Participant
July 22, 2009

Thanks so much GKaiseril! The document you linked me to was very useful and I was able to play around with coordinates to create a good header.

For anyone looking to get a header script, here's what I have:

app.addSubMenu({ cName: "Header",cUser: "Set/Remove Header", cParent: "File", nPos: 20 });

app.addMenuItem({ cName: "Set Date Time (Filename)", cParent: "Header", cExec: "SetHeader(1)"});
app.addMenuItem({ cName: " ->  Set Date .... centered", cParent: "Header", cExec: "SetHeader(2)"});
app.addMenuItem({ cName: " ->  Set Date .... right", cParent: "Header", cExec: "SetHeader(3)"});
app.addMenuItem({ cName: "Set Page centered", cParent: "Header", cExec: "SetHeader(4)"});
app.addMenuItem({ cName: " -> Set Page right", cParent: "Header", cExec: "SetHeader(5)"});
app.addMenuItem({ cName: "Set Both", cParent: "Header", cExec: "SetHeader(9)"});

app.addMenuItem({ cName: "-------------------------------", cParent: "Header",cExec: "{}"});

app.addMenuItem({ cName: "Remove Both", cParent: "Header", cExec: "RemoveHeader(9)"});
app.addMenuItem({ cName: "Remove Date Time (Filename)", cParent: "Header", cExec: "RemoveHeader(1)"});
app.addMenuItem({ cName: "Remove Page", cParent: "Header", cExec: "RemoveHeader(4)"});


//Set/remove Header
function SetHeader(ARG)
{
var re = /.*\/|\.pdf$/ig;
var FileNM = this.path.replace(re,"")+".pdf";
var Path = this.path;
var AcDate = new Date();
var AcDateFormat = "yyyy/mmm/dd  HH:MM"
var Box2Width = 50
for (var p = 0; p < this.numPages; p++)
{
  var aRect = this.getPageBox("Crop",p);
  var TotWidth = aRect[2] - aRect[0]
  if (ARG<=3 || ARG==9)
   { var fd = this.addField("xftDate", "text", p, [30,1450, TotWidth-30-30,30]);
      fd.value =  util.printd(AcDateFormat, AcDate) + "   (" + FileNM +")";
       fd.textSize=12; fd.readonly = true;
       if (ARG==1){ fd.alignment="left" };
       if (ARG==2){ fd.alignment="center" };
       if (ARG==3){ fd.alignment="right" };
    }
  if (ARG==4 || ARG==5 ||ARG==9)
   {  var hStart=(TotWidth/2)-(Box2Width/2)
       var hEnd=((TotWidth/2)+(Box2Width/2))
       if (ARG==5){var hStart=(TotWidth-Box2Width-30); var hEnd=(TotWidth-30);}
       var fp = this.addField(String("xftPage"+p+1), "text", p, [hStart,30,hEnd,1450]);
       fp.value = "Page: " + String(p+1)+ "/" + this.numPages;
       fp.textSize=12;  fp.readonly = true;
       fp.alignment="center";
   }
}
}

function RemoveHeader(ARG)
{
if (ARG<=3 || ARG==9) {var x = this.removeField("xftDate");}
if (ARG==4 || ARG==9)
   {  for (var p = 0; p < this.numPages; p++)
      {var x = this.removeField(String("xftPage"+p+1)); }
   }
}

Thanks again for your help!