I added the following code to the will print event in.. worked like a charm. Copy and paste the following if you ever need your PDF to print date and path of the file on the footer of the PDF.
var f = this.getField("Today");
f.value = util.printd('dddd mmmm dd yyyy h:MM tt ', new Date())+ "("+this.path +")";
Thanks
Have you tried running the code?
The 'util.printd()' is a method to format the JS data time object. What is displayed is controlled by the formatting string entries to select the elements of the date time and how to format those selected elements.
For example the above code will create the following string:
"Thursday May 26 2011 3:07 pm (/C/Program Files/Adobe/Acrobat 8.0/Help/ENU/JS_api_reference.pdf)"
With additional programing, you can even get the timezone offset and the UTC time.
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";
}
}
}
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!
"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
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, Re: Print File Name with pdf Document);
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...
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
" ... 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
Reinhard,
Greetings. I just found your script for adding the footnote that includes the date and the file path to the page. I also read the many subsequent posts to your code. Can you tell me which post/code that will print the footnote, but does not throw the warning when you press the 'Yes' button when the "Warning: JavaScript Winow Delete Date / Filename"?
Many thanks for the code and any help you can give. I am working in Adobe Acrobat 9.4.6 if that helps?
Thanks,
Richard
Mmmh,
I'm not sure what script you used:
1. SetRemoveFooter.js ( = folder level javascript, which produce a Menuitem "Set/Remove Footer" under File) or
2. AcFooterBatch.vbs ( = VBScript which uses activeX to execute from 1. extracted footer javascript in a batch via drag and drop or commandline)
In 1. is no button, in 2. is only OK/Cancel button. For me both works without warning (AAv9.2.0). The only setting I change from standard is the presetting for javascipt (under edit). I marked the second selection (execute js via menuitem). Perhabs you test that.
best regards, Reinhard
PS: Menitems description free translated from german verrsion
Hi,
it seems you have an older version. In the latest you can choose if you only want to print Date and filename only.
The latest version you can download from:
http://www.Refob.de/downloads/acrobat/SetRemoveFooter.js
If you have the old version I assume you can delete or comment out (= write // in the front of the text) this lines:
var fp = this.addField(String("page"+p+1), "text", p, [330,10,280,28]); //<- this set up the page number file
fp.textSize=8; fp.value = "Page: " + String(p+1)+ "/" + this.numPages; //<- this fomat the page number field
If that not help, please copy in the js-code you work with, so also other with a more compareable working time, can give you the small changes.
best regards, Reinhard
Thanks, I have allready changed those two lines.
But I would also get rid of all lines that is about page numbers, because I will not use that.
How to change the line : fd.value = util.printd .........................
to show the full path first an then the date?
Thanks in advance!
Best regards
Arne
Reinhard,
Dies ist eine sehr gute Arbeit!
I have read this thread with interest since I nioticed it today and have placed your JavaScript in my Acrobat 6.0 install folder. I have been able to make modifications to the components of the footer (date format, adding PRELIMINARY to the textstring, changing text size). It works very well and gives me a new tool for identifying preliminary versions of manuals.
Would you explain how to change the location of the footer? I would like to place it a little higher on the page.
BTW, I noticed that Acrobat has a feature called Add Headers & Footers but it is much more time consuming to use and does not have the flexibility, ease of use, and performance of your script.
Danke,
Michael F
=======
Danke Michael,
habe einfach nicht die Zeit es mal komplett - mit mehr Optionen - zu überarbeiten.
"Would you explain how to change the location of the footer? I would like to place it a little higher on the page."
You can inrease the y-coordinates: upper left (y1) and lower right (y2):
If you want the field 10 Pts higher you can change:
var fd = this.addField("xftDate", "text", p, [30,15, TotWidth-30-30,30]);
to
var fd = this.addField("xftDate", "text", p, [30,15+10, TotWidth-30-30,30+10]);
The difference between y1 and y2 is the field hight.
The calculation for the field placing on the page start at lower left corner (= 0).
HTH, Reinhard
This goes both to ReinhardF and Michael314!
I'm a total novise as far as programming is concerned. I have ReinhardF's javascript and it works perfect i AA X.
I wonder if some of you experts could make me a Javascript that show the full file path and nothing else on the first page only of a document as a footer.
Please give me the option of choosing between left, center or right position.
Thanks!!!!
Best regards
Arne
Arne,
Reinhard did give you a hint back in post 124.
Change the fd.value statement to this:
fd.value = "Path: " + Path;
When you open the PDF file and select any of the Set Date... commands, it will insert only the file path.
I think the pages affected are controlled by this statement but I don't know how to adjust it.
for (var p = 0; p < this.numPages; p++)
Yours,
Michael F
=======
"I think the pages ..." thats correct.
@ Arne
Change:
for (var p = 0; p < this.numPages; p++)
to
for (var p = 0; p < 1; p++)
to get it only on the first page, or:
for (var p = 1; p < this.numPages; p++)
to get it on all, but not on first.
The second question: "Please give me the option of choosing between left, center or right position" astonished me. It's already in the menu selection. I think at least you can test the script before asking.
best regards, Reinhard
Hello ReinhardF
great script, just does what I expected. One Question
Line:
| & " | fd.textSize=6; "&vbLF _ |
I changed Textsize to 10 and it works fine, but is there a possibility to get the textstyle bold? I tried:
| & " | fd.textStyle=bold; "&vbLF _ |
but didn't work. I don't to the Scripting Parameters so I ask in this Forum.
Hi,
there exists no property "textStyle". You have to choose a font in bold. So font: font.TimesB, font.HelvB, font.CourB
###can be used. If you add a I at the end it will be bold+Italic.
So you can Write (in above VBS file):
&" fd.textSize=10; fd.textFont = font.TimesB; "&vbLF_
Pay attention to the point that JS is case sensitive.
Load down the AcroJs.pdf helpfile and have a look at the Field Object -> Field properties.
So you may use textColor or fieldBorder or ...
Good luck, Reinhard
PS: That just gives me the idea to change the VBS-files so that the js-variable will be set by reading saved poor JS-Code.
That avoid the change to vbs-writing (&" "&vbLF), the js-code could directly tested in the acrobat-js-console and all saved versions could be executed by selecting the file. I think I will put it on my list.
Reinhard,
To give users some variety, they can also use non-bold fonts, so brief font list looks like this:
fd.textFont = fontname;
where fontname can be:
font.Times
font.TimesB
font.Helv
Font.HelvB
font.Cour
font.CourB
We're taqlking about text in a footer, so you should not need more variety than this.
Yours,
Michael F
========
@Arne
simple delete or comment out (like as follow) these lines:
// app.addMenuItem({ cName: "Set Page ", cParent: "Footer", cExec: "SetFooter(4)"});
// app.addMenuItem({ cName: "Set Both", cParent: "Footer", cExec: "SetFooter(5)"});
// app.addMenuItem({ cName: "Remove Both", cParent: "Footer", cExec: "RemoveFooter(5)"});
// app.addMenuItem({ cName: "Remove Page", cParent: "Footer", cExec: "RemoveFooter(4)"});
The statement cName:"..xxx.." is only the menu item display name. So you change it for rest to whatever you want-
Good luck, Reinhard
@Reinhard
Thank you very much for your useful script and your helpful replies to users questions here. This will streamline my workflow 100x
I've taken the script in AA X and modified page position to fit specific documents.
As a quick guide to help others, initially I didn't have a good grasp on the placement syntax and would like to share with others here what I "figured out".
[10,30,545,40]
10 = Places the start of the text box 10 pixels from the left most edge (x1 coordinate) of the document
30 = Places the bottom of the text box 30 pixels from the bottom (y1 in your post) edge of the document
545 = Places the end of the text box 545 pixels from the left most edge (x2 coordinate) of the document (ie. 535 pixel wide text box, starting 10 pixels from left most edge)
40= Places the top of the text box 40 pixels from the bottom edge (y2 in your post) of the document (ie. 10 pixel high text box)
Is this logic correct?
Also, I plan to share this with other collegues in my office, I would like to put the following header in the script, with your permission. If you would like me to add any other credit text, please post it or send via PM
//Original script written by ReinhardF, Nov 13, 2006
//For specific questions, visit http://forums.adobe.com/thread/302996?tstart=0
Thanks again!
Is there a way to rotate the text 90 degrees?
I have documents that have text at the top most and bottom most part of the page, but an inch of whitespace on the right hand side.
What I'm hoping to do is have text run along the right-hand side and when the page is in a 3-ring binder, the text is running LR reading order starting in the lower right corner, running up to the top right side of the page.
Thanks
Hi,
"Is this logic correct?" -> Yes it is.
"Also, I plan to share" -> No problem.
"Is there a way to rotate the text 90 degrees?" No problem : fd.rotation=90
found at; AcroJs.pdf Field object -> Field property =>rotation
"have text run along the right-hand side " Not realy a porblem, you need: var TotHeight = aRect[1] - aRect[3];
found at; AcroJs.pdf Doc object -> Doc methods = > getPageBox
With that you have all information to set it als header, in the middle or wherever you want.
Good luck, Reinhard
Hi ReinhardF!
I have tried to modify the script to meet my needs, that is ONLY the filepath to be shown on the first page only, no need for page number or date.
My script looks like this:
app.addSubMenu({ cName: "Footer", cUser: "File Path", cParent: "fil", nPos: 20});
app.addMenuItem({ cName: "Left", cParent: "Footer", cExec: "SetFooter(1)"});
app.addMenuItem({ cName: "Center", cParent: "Footer", cExec: "SetFooter(2)"});
app.addMenuItem({ cName: "Right", cParent: "Footer" , cExec: "SetFooter(3)"});
app.addMenuItem({ cName: "Remove", cParent: "Footer", cExec: "RemoveFooter(1)"});
function SetFooter(ARG)
{
var re = /.*\ / | \ .pdf$/ig;
var Path = this.path;
var Box2Width = 50
for (var p = 0; p < 1; 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 = Path;
fd.textSize=6; fd.readonly = true;
if (ARG==1){ fd.alignement="left" };
if (ARG==2){ fd.alignement="center" };
if (ARG==3){ fd.alignement="right" };
}
if (ARG==4 | | Arg==5 | | ARG==9)
{ var bStart=(TotWidth/2)-(Box2Width/2)
var bEnd=((TotWidth/2+8Box2Width/2))
if (ARG==5){var bStart=8TotWidth-Box2Width-30); var bEnd=(TotWidth-30);}
var fp = this.addField(String("xftPage"+p+1), "text" , p, [bStart, 30, bEnd, 15]);
}
}
}
Function RemoveFooter(ARG)
{
if (ARG<=3 | | ARG===9) {var x = this.removeField("xftDate");}
}
Is ther anything more I can remove from this script, and still make it to work for the file path only?
Just to reduse the script to a minimum.
Thanks from Arne!
North America
Europe, Middle East and Africa
Asia Pacific