Skip to main content
Participant
August 30, 2006
Question

Print File Name with pdf Document

  • August 30, 2006
  • 93 replies
  • 245472 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

Participating Frequently
March 14, 2007
Fantastic with the JS.

Thanks to Reinhard and You all.

I'm a 100% novice in this.

But the

var re = /.*\/|\.pdf$/ig;
var FileNM = this.path.replace(re,"")+".pdf";
var Path = this.path;

doesn't seem to work by me. The filename is always "NaN.pdf".

However - after a look in the js api documentation, I changed the 3 lines to just

var FileNM =this.documentFileName

It seems to work. Am I missing something?
Participant
March 14, 2007
Hi

I've been struggling to create an excel document which needs to go out with a header in the form of our company logo. As Excel has very limited layout capabilities, is it possible to use your script to add a header which just includes a (positioned) logo to an excel file being printed to PDF?

Thanks
Participant
March 14, 2007
Reinhard,

I have altered your code a bit for my specific needs...I need the month/day/time, then document name on the left hand side of the footer, the page of pages in the center...which you have...but then also...on the right hand side of the page, I need it jus plain text where I can type in a message....the code that you've written is a fantastic start...I jus need to figure out how to get that last part in there..and im fairly new to all this...plus..I don't know if removing stuff, I've messed up the other code...seems functional when I test it, but it maybe a bit sloppy after me messing with it!...how do I add that last piece of code? Thanks for your help!!

app.addSubMenu({ cName: "Footer",cUser: "Test", cParent: "File", nPos: 20 });

app.addMenuItem({ cName: "Set", cParent: "Footer", cExec: "SetFooter(9)"});

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

app.addMenuItem({ cName: "Remove", cParent: "Footer", cExec: "RemoveFooter(9)"});

//Set/remove Footer
function SetFooter(ARG)
{
var re = /.*\/|\.pdf$/ig;
var FileNM = this.path.replace(re,"")+".pdf";
var Path = this.path;
var AcDate = new Date();
var AcDateFormat = "mm/dd/yyyy 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==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==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";
}
}
}

function RemoveFooter(ARG)
{
if (ARG==9) {var x = this.removeField("xftDate");}
if (ARG==9)
{ for (var p = 0; p < this.numPages; p++)
{var x = this.removeField(String("xftPage"+p+1)); }
}
}
ReinhardF
Participating Frequently
March 14, 2007
1.)Dateformat
Change the line:
var AcDateFormat = "yyyy/mmm/dd HH:MM"
to your needs, like:
var AcDateFormat = "mm/dd/yyyy"

For more Date formats have a look at the JavaScript help file:
http://www.adobe.com/devnet/acrobat/pdfs/js_api_reference.pdf#page=716

2.)document will expire
A simple solution would be (see "answer #8"):
- the first box (Date ...) uses the total width of the page. So it also useable if you want to have a selfmade footer note, something like "First Draft from ....". You have only to edit one box on one page, then it will be displayed on all pages.

Another solution would be to set up an extra field (box) for that.

HTH, Reinhard
Participant
March 14, 2007
This is fantastic...just what I was look for!...I just need to add a line of text stating the document will expire after so many days and the date and time to be ...mm/dd/yyyy and standard time not military time. What do I need to add and/or change to achieve this?
ReinhardF
Participating Frequently
March 11, 2007
In the line:

fd.value = util.printd(AcDateFormat, AcDate) + " (" + FileNM +")";

replace FileNM with Path.

Best regards, Reinhard
Participant
March 10, 2007
Reinhard, I love this Javascript for printing the file name as a footer on Acrobat documents; however, I DO need the whole path name as well as the file name to print on my documents...how do I fix this script so that this will happen? Thanks
~graffiti
Legend
November 17, 2006
Jeffrey,

Click the "Show all messages" link towards the top of the thread and you'll see his post.
Participating Frequently
November 17, 2006
Hello Reinhard,

The script you modified on 16 Nov does not appear in the forum posting, so I cannot copy and paste it. However, if you can email it to me at **** I would very much appreciate it.

Thanks and regards,

Jeff
ReinhardF
Participating Frequently
November 17, 2006
Just remembered to some Webspace I have. You can download from:

http://www.Refob.de/downloads/acrobat/SetRemoveFooter.js

HTH Reinhard