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
July 16, 2009

I'm trying to get a simple FilePath/Document Name footer via the JS window in Acrobat Pro 7.1.0 and don't see the menu option under File->Print after a restarting of Acrobat.  No error messages, just no menu item.

I've copied the following text to this location: C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Javascripts\PrintWithFooter.js


// 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)); }

} }

I do however have the following code working in the JS Editor inside of Acrobat:

this.addWatermarkFromText({cText: (this.path), nRotation:0, nVertValue:-124});

When I try to reduce the font size using:

this.addWatermarkFromText({cText: (this.path), nRotation:0, nVertValue:-124, fontSize: 8});

It's the same size as without the fontSize code, is there proper syntaxt that will get the font smaller?

Also, is there a way to not get the absolute path, but the drive letters?

This: this.addWatermarkFromText({cText: (this.path), nRotation:0, nVertValue:-124});

results in this:
/domain/drive/unit/remote/UserName/Creating Custom Labels.pdf

but I would like:


Y:UserName/Creating Custom Labels.pdf

Thanks

Inspiring
July 16, 2009

If you check the Acrobat JavaScripting documentation, folder level scripts are only processed upon opening the application, so you will need to exit and shutdown Acrobat and any web browser using the PDF plug in and restart Acrobat to get the menu item established.

When specifying the parameter name, one needs to use the parameter name in the documentation. The parameter name for the font size is "nFontSize" to specify the number in points for the font size.

Participant
July 16, 2009

GKaiseril wrote:

If you check the Acrobat JavaScripting documentation, folder level scripts are only processed upon opening the application, so you will need to exit and shutdown Acrobat and any web browser using the PDF plug in and restart Acrobat to get the menu item established.

No luck.  I even rebooted the PC and when I open Acrobat, it's still not there.

GKaiseril wrote:

When specifying the parameter name, one needs to use the parameter name in the documentation. The parameter name for the font size is "nFontSize" to specify the number in points for the font size.

That did it!  Oversight on my part.  Any ideas for the file path question (the way the syntax is a full path vs a drive letter?)

Thanks for getting me this far.

Participant
March 27, 2009
This is probably due to the document having security settings. Try a PDF w/o security. Download a program that strips the document of the Restrictions. This works most of the time for this error.

REPLY TO: Eli R Kaplan, "Print File Name with pdf Document" #27, 16 Apr 2007 1:16 pm

>QUOTE=====

>Eli R Kaplan - 1:16pm Apr 16, 07 PST (#27 of 79)

>I got the "Set/Remove Footer" thing to show up above print setup under the file drop-down, but when I click on any of the options it says, "an internal error occurred"

>Is this because I have Vista? any advice?
thanks for your help

----------------------------------------------------
>Reinhard Franke - 3:49am Apr 17, 07 PST (#28 of 79)

>"Is this because I have Vista? any advice?"

>I don't know. Which Acrobat version?
>You may test the pure script (without app.addMeuitem) in the JS->Console.

>best regards, Reinhard

>END QUOTE =================
Participating Frequently
November 22, 2008
Geo,

This works perfectly; I will have to decipher what determines the placement, but until then this will do fine.

Thanks again.

@ Jeffrey Kuhn, if you control click the acrobat program in OSX and select show package contents, you can navigate to the javascript folder (it's a subfolder within mac os i think). i've confirmed that the menus are modified by the scripts but haven't actually tried them.
Inspiring
November 20, 2008
I just changed the code for the PrtFooter fucntion.

So an applicaiton JS File could look like:

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

function PrtFooter() {
var sFirstLine = "Date: " + util.printd("yyyy/mmm/dd", new Date()) + " (" + this.path +")\r"; // first line
var sSecondLine; // second line
for(p = 0; p < this.numPages; p++) {

sSecondLine = "Page: " + String(p+1)+ "/" + this.numPages; // second line
this.addWatermarkFromText({
cText: sFirstLine + sSecondLine,
nFontSize: 8,
aColor: color.green,
nStart: p,
nEnd: p,
nTextAlign: app.constants.align.left,
nHorizAlign: app.constants.align.left,
nVertAlign: app.constants.align.bottom,
bOnScreen: false,
bOnPrint: true
});

} // end page loop
// this.print();
this.dirty = false; // cancel save prompt flag
} // end PrtFooter function

You may need to fine tune it to get it placed exactly on the page. More information is contained in the Acrobat JavaScript API Reference.
Participating Frequently
November 20, 2008
Geo,

How does this work? How do I invoke the script?

It doesn't appear to modify the menus or the print dialog box.

Thanks.
Inspiring
November 20, 2008
You could use the doc "addWatermarkFromText()" method.

For example:

function PrtFooter() {
var sFirstLine = "Date: " + util.printd("yyyy/mmm/dd", new Date()) + " (" + this.path +")\r"; // first line
var sSecondLine; // second line
for(p = 0; p < this.numPages; p++) {

sSecondLine = "Page: " + String(p+1)+ "/" + this.numPages; // second line
this.addWatermarkFromText({
cText: sFirstLine + sSecondLine,
nFontSize: 8,
aColor: color.green,
nStart: p,
nEnd: p,
nTextAlign: app.constants.align.left,
nHorizAlign: app.constants.align.left,
nVertAlign: app.constants.align.bottom,
bOnScreen: false,
bOnPrint: true
});

} // end page loop
// this.print();
this.dirty = false; // cancel save prompt flag
} // end PrtFooter function
Participating Frequently
November 20, 2008
Bernd,

We had some network problems in our office and I had to restart my computer; the scripts now appear correctly, though I am not sure why(the script to add a comment field however gives me an error that I am missing a ';' in line 18).

I applaud everybody's input and thank you once again.

I have a couple question

Is there a way to get a script that will add these items as a print watermark rather than to the file itself? Then if the file path changes the printed path would always be correct.

Is there a way to incorporate the 'Appearance Option' that specifies to 'Shrink document to avoid overwriting'?

Thanks.
ReinhardF
Participating Frequently
November 20, 2008
@KPanthen

Codeline:
fp.value = "Page: " + String(p+1)+ "/" + this.numPages;
replace with:
fp.value = "FINAL PRINT COPY " + String(p+1)+ "/" + this.numPages;

Codeline:
fp.textSize=6; fp.readonly = true;
replace with:
fp.textSize=6; fp.readonly = true;fp.textColor = color.green;

Maybe you set the fp.textSize=6 to 8 or 10, then you see the color better.

I didn't test if the box is width enough for that.
If not come back.

Best regards, Reinhard
Inspiring
November 20, 2008
If you are using version 6 or above, try the following script in the JavaScript Debugging console or add to a form button action:

var sJSFolder = "JavaScript folders for " + app.viewerType + " are:";
try {
sJSFolder += "\nApplicaiton JavaScript folder; " + app.getPath("app","javascript");
sJSFolder += "\nUser JavaScirpt folder; " + app.getPath("user","javascript");
} catch(e) {
sJSFolder += "User has not defined any application JavaScripts";
}
console.show();
console.println(sJSFolder);

You can then chose where to put the script.
November 20, 2008
I have been looking and really can't decifer where it should go. Can anyone help in the actual placement of the coding?

KPanthen, New York