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

ReinhardF
Participating Frequently
November 17, 2006
I think there is no need. I copied it out and in and it works fine for me (AAr5).

However you may state where to sent to and you will get it.

br, Reinhard
Participating Frequently
November 16, 2006
Thanks. Can you post it?

Regards

Jeff
ReinhardF
Participating Frequently
November 16, 2006
I've edited above script and now it should work.

br, Reinhard
Participating Frequently
November 16, 2006
Hi Reinhard,

Thanks for working on this. However, this script does not work, because the "Set/Remove Footer" submenu does not appear in my File menu (the previous version worked fine). I have carefully copied and pasted your script into a new .js file in the \javascripts folder. What could I be doing wrong?

Jeff
ReinhardF
Participating Frequently
November 16, 2006
OK! Did a little bit more so it is usable for myself.

Now you can choose if you want to have the "Date Time (Filename" footer want to have left, center, or right aligned.

The code has been updated:
- now it really cnter the boxes page for page.
- 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.

- if you want to remove you can use allways "Remove both". It's only work a little bit longer in bigg files.

br, Reinhard

PS to other scripters: If someone has time he may improve the script.
The general settings could be done on a extra page (like general Dateformat, general Texthigh, ..... Then this can saved in global.js. So all the user defined settings are stored and retrieveable. That would Adobe save work. Adobe should set up a "Acrobat Scripts & Scraps" forum, where (freetime-)scripter can publish and discuss scripts.

Edit: ... and where it is also possible to publish scripts without to have to format by yourselft, so that it is readable!

SetRemoveFooter.js (<-Save in folder ...\javascript)

-----------------------------------------------


// SetRemoveFooter

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


app.addMenuItem({ cName: "Set Date Time (Filename)", cParent: "Footer", cExec: "SetFooter(1)"});

app.addMenuItem({ cName: " -> Set Date .... centered", cParent: "Footer", cExec: "SetFooter(2)"});

app.addMenuItem({ cName: " -> Set Date .... right", cParent: "Footer", cExec: "SetFooter(3)"});

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

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


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


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

app.addMenuItem({ cName: "Remove Date Time (Filename)", cParent: "Footer", cExec: "RemoveFooter(1)"});

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


//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 = "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==5)

{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)

{var bStart=(TotWidth/2)-(Box2Width/2)

var bEnd=((TotWidth/2)+(Box2Width/2))

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<=3 || ARG==5) {var x = this.removeField("xftDate");}

if (ARG==2 || ARG==5) {for (var p = 0; p < this.numPages; p++)

{

var x = this.removeField(String("xftPage"+p+1)); }

} }
ReinhardF
Participating Frequently
November 15, 2006
Attached an updated Script. It gives you a menu for Set/Remove Footer. Then you can Set - Print - Remove.

HTH, Reinhard

PrintWithFooter.js
-------------------------------

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

app.addMenuItem({ cName: "Set Date Time (Filename)", cParent: "Footer", cExec: "SetFooter(1)"});
app.addMenuItem({ cName: "Set Page ", cParent: "Footer", cExec: "SetFooter(2)"});
app.addMenuItem({ cName: "Set Both", cParent: "Footer", cExec: "SetFooter(3)"});

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

app.addMenuItem({ cName: "Remove Date Time (Filename)", cParent: "Footer", cExec: "RemoveFooter(1)"});
app.addMenuItem({ cName: "Remove Page", cParent: "Footer", cExec: "RemoveFooter(2)"});
app.addMenuItem({ cName: "Remove Both", cParent: "Footer", cExec: "RemoveFooter(3)"});

function SetFooter(ARG)
{
var re = /.*\/|\.pdf$/ig;
var FileNM = this.path.replace(re,"")+".pdf";
var Path = this.path;
var AcDate = new Date();
for (var p = 0; p < this.numPages; p++)

{

if (ARG==1 || ARG==3) {var fd = this.addField("xftDate", "text", p, [30,15, 290,30]);

fd.textSize=6; fd.value = util.printd("yyyy/mmm/dd, HH:MM", AcDate) + " (" + FileNM +")"; }

if (ARG==2 || ARG==3){var fp = this.addField(String("xftPage"+p+1), "text", p, [350,15,300,30]);

fp.textSize=6; fp.value = "Page: " + String(p+1)+ "/" + this.numPages; }

} }

function RemoveFooter(ARG)
{

if (ARG==1 || ARG==3) {var x = this.removeField("xftDate");}

if (ARG==2 || ARG==3) {for (var p = 0; p < this.numPages; p++)

{

var x = this.removeField(String("xftPage"+p+1)); }

} }
Participating Frequently
November 14, 2006
Thank you Reinhard! You were kind to do this; but if I may ask a favor, can I get a version that just prints the date and the file name? I don't need the file path, since it's very long anyway.

Also, this script crashes when one chooses the "yes" option on the remove dialog.

Many thanks
ReinhardF
Participating Frequently
November 13, 2006
Attached a simple JS that will do it. Copy it into Notepad and save it in your Acrobat \Javascript folder. Next time you start Acrobat you will a have menuitem "Print with Footer" direct above Print.

It put the values into fields at the footer. That may took some time. Then it displays the print-dialog and finaly you can choose if you want to remove the fields or not.

Enjoy, Reinhard

PrintWithFooter.js
-------------------------------

app.addMenuItem({cName:"Print with Footer", cParent:"File", nPos:20, cExec:"PrtFooter();"});

//Print bookmarked Pages
function PrtFooter()
{

for (var p = 0; p < this.numPages; p++)

{

var fd = this.addField("Date", "text", p, [10,10, 300,28]);
fd.textSize=8; fd.value = "Date: " + util.printd("yyyy/mmm/dd", new Date()) + " (" + this.path +")"

var fp = this.addField(String("page"+p+1), "text", p, [330,10,280,28]);

fp.textSize=8; fp.value = "Page: " + String(p+1)+ "/" + this.numPages;

}

app.execMenuItem("Print");

var OK = app.alert("Delete Date / Filename?",2,2);

if (OK == 4) {

var x = removeField("Date");

for (var p = 0; p < this.numPages; p++)

{

var x = removeField(String("page"+p+1));

} }

}
Participant
May 25, 2011

So this works with PRO but does anyone have script that will work

with Reader?

Participant
May 25, 2011

The code will be saved as part of the pdf file, so regardless of where you run it, Reader of Pro or Standard the code will execute. I saved the PDF in pro and all the users that read our documents use Reader to read the pdf file. Once they go to print the file the code executes.

Participating Frequently
November 13, 2006
I read your question as how to do that for a particular document - so yes, the embedded JavaScript would need to be included in that document. You could certainly have this done on the server as well, as part of your creation process.

As to have Acrobat do this - although Acrobat itself doesn't include this functionality - I believe there are some 3rd party plugins for Acrobat that can add this.

Leonard
Participating Frequently
November 13, 2006
Ok, thanks, but I don't know JavaScript, and even if I did your answer suggests that it needs to be done de novo for each document for which you need this information. We create many documents each day from a web-based banking application, and it would be great if Acrobat would simply handle this. I'm amazed Adobe hasn't built this in.

If I've misunderstood the custom nature of your solution, please let me know. And if you'd care to toss in some JavaScript, great!

:)

Thanks.