Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
How can this be done?
Contact support
http://www.xemtruyenhinh.info/
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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";
}
}
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
"I'm sure the problem is obvious, but I'm very new to this."
So then start simple and keep it simple.
Your startup I stated already to you, so take that for testing until you get it to work:
SetFooterBatch(2);
function SetFooterBatch(ARG)
{
........
-------
}
ARG is a variable, means arguments.
As arugments you can only only take 1-5 or 9.
Have a look at the menuitems in the full script to understand for what it stands.
But once again, start simple, get above to run and then you can go on.
HTH, Reinhard
Copy link to clipboard
Copied
I should have said, "I'm sure the problem is obvious to you, but it is not to me because I don't know much about programming. I'm just a government stiff trying to make sure that the taxpayer is getting his/her money's worth by spending more time doing my job rather than manually putting the filename into the footer of every file. So, if you could provide the straight code to do a batch process instead of making me guess, that would be great!"
But, just for the record, I did give it a shot. I want to make argument 1 rather than 2, so I made the replacement, and it still didn't work. Then, I just deleted all the other arguments and - you guessed it - it didn't work. Here's the shortened code I used:
{
var re = /.*\/|\.pdf$/ig;
var FileNM = this.path.replace(re,"")+".pdf";
var AcDate = new Date();
var AcDateFormat = "yyyy/mmm/dd HH:MM";
for (var p = 0; p < this.numPages; p++)
{
var aRect = this.getPageBox("Crop",p);
var TotWidth = aRect[2] - aRect[0];
var fd = this.addField("xftDate", "text", p, );
fd.value = util.printd(AcDateFormat, AcDate) + " (" + FileNM +")";
fd.textSize=6;
fd.readonly = true;
fd.alignment="left";
}
}
I even threw in "function SetFooterBatch(ARG)" at the top, and then "SetFooterBatch(1)" above that. Still didn't work...
Copy link to clipboard
Copied
Mmmh,
at least you are nearby. If you replace in your shortened code:
var fd = this.addField("xftDate", "text", p, 30,15, TotWidth-30-30,30);
with the correct one (which includes []):
var fd = this.addField("xftDate", "text", p,[30,15,TotWidth-30-30,30]);
then the code works and you will get on every file and page left alined something like: 2011/Aug/08 14:55 (file01.pdf)
If that not works, perhabs someone with an english acrobat version can lead you through the steps how to set up a batch job. I'm afraid my translation from german to english would be to bad.
HTH, Reinhard
Copy link to clipboard
Copied
Actually, for some reason, the forum's text editor recognized the brackets as a link. So, I did have the brackets in there, and yes, it still doesn't work. Anyway, I'll try elsewhere. Thanks for your help.
Copy link to clipboard
Copied
" ... trying to make sure that the taxpayer is getting his/her money's worth by spending more time doing my job rather then ..."
Ok, I think that's a good reason for a last try.
Because we don't get it to work direct in Acrobat I wrote a VBScript for that. I think the smartphone-generation would call it an "App" 🙂
Copy the following vbs into an editor (like Notepad) and save it as AcFooterBatch.vbs on your desktop.
Drag and drop from explorer some files on it and you will get it back with footer.
HTH, Reinhard
AcFooterBatch.vbs
-----------------------------
'////// User settings /////////////////////////////////////////////////////////
fileSaveDir = "c:\Temp" '/->state an existing folder for saving changed files
mode = 1 '/-> 0=work hidden; 1= show acrobat
test = 1 '/-> 0= don't show messages; 1=show messages
'///////////////////////////////////////////////////////////////////////////////
' // set WSH objects
set oWsh = CreateObject ("Wscript.Shell")
Set oArgs = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
' // test basic files/folders
if not fso.FolderExists(fileSaveDir) then : msgBox("Folder """ &fileSaveDir &""" don't exist") : wscript.quit : end if
if oArgs.Count = 0 then : MsgBox("Drag & Drop files on this") : Wscript.quit : end if
' // set acrobat basic objects
Set App = CreateObject("Acroexch.app")
if mode > 0 then app.show
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
' // write acro-js to a variable for later executing
Ex = " // set Date and filename as footer "&vbLF _
& " var re = /.*\/|\.pdf$/ig; "&vbLF _
& " var FileNM = this.path.replace(re,"""")+"".pdf""; "&vbLF _
& " var AcDate = new Date(); "&vbLF _
& " var AcDateFormat = ""yyyy/mmm/dd HH:MM""; "&vbLF _
& " for (var p = 0; p < this.numPages; p++) "&vbLF _
& " { "&vbLF _
& " var aRect = this.getPageBox(""Crop"",p); "&vbLF _
& " var TotWidth = aRect[2] - aRect[0]; "&vbLF _
& " var fd = this.addField(""xftDate"", ""text"", p, [30,15, TotWidth-30-30,30]); "&vbLF _
& " fd.value = util.printd(AcDateFormat, AcDate) + "" ("" + FileNM +"")""; "&vbLF _
& " fd.textSize=6; "&vbLF _
& " fd.readonly = true; "&vbLF _
& " fd.alignment=""left""; "&vbLF _
& " } "
' // kernel: batch processing of js-code
for each xFile in oArgs
if test = 1 then : OK = msgbox("Change file: " & xFile,1) : if OK = 2 then WScript.quit : end if
If not fso.FileExists(xFile) Then : msgbox("File doesn't exist") : wscript.quit : end if
If AVDoc.Open(xFile,"") Then
set PDDoc = AVDoc.GetPDDoc
AForm.Fields.ExecuteThisJavaScript Ex
outFile = fileSaveDir &"\" &mid(xFile,InstrRev(xFile,"\")+1)
if test = 1 then : OK = msgbox("Script executed"&vbCr&"SaveAs: "&outfile,1) : if OK = 2 then WScript.quit : end if
If fso.FileExists(outFile) Then fso.DeleteFile(outfile)
PDDoc.save 1, outFile
App.CloseAllDocs
else
msgbox("Coudn't open file!") : wscript.quit
end if
next
OK = msgbox("Batchjob finished!" &vbCr &"Close Acrobat?",1) : if OK = 1 then app.exit
Set AVDoc = Nothing : Set PDDoc = Nothing
Set APP = Nothing : Set AForm = Nothing