These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

page numbers with javascript

kr4z33
Registered: Apr 25 2007
Posts: 6

i need to add some page numbers with a prefix to a bunch of documents, I am following:

http://www.planetpdf.com/enterprise/article.asp?ContentID=adding_page_number_to_pdfs&gid=6048

which does it with some javascript attached to a button but Its not working for me. I click the button and nothing visible happens. heres my code:

var r = [612-72, 792 - 72, 612, 792];
//inch from upper right
 
 
for (var i = 0; i < numPages; i++) {
    var f = this.addField(string("page"+i+1),"text",i,r);
    f.textSize = 20;
    f.textColor = color.black;
    f.fillColor = color.red;
    f.textFont = font.helvB;
    f.borderStyle = border.s;
    f.strokeColor = color.transparent;
    f.value = String(i+1);
}

does anything look wrong? I inserted some alerts and the script is indeed running.

kr4z33
Registered: Apr 25 2007
Posts: 6
argh, just typos, this works:

var prefix = app.response({cQuestion: "prefix before page numbers?",cTitle: "add numbers !"}); var r = [612-72, 792 - 72, 612, 792];//inch from upper right for (var i = 0; i < numPages; i++) {var f = this.addField(String("page"+i),"text",i,r);f.textSize = 14;f.textColor = color.black;f.fillColor = color.white;f.textfont = font.HelvB;f.borderStyle = border.s;f.strokeColor = color.transparent;f.value = String(prefix+i);}

have a nice day !
carisima
Registered: Apr 25 2008
Posts: 21
I'm using this script to add page numbers to my document. I need to change the text font, but it doesn't seem to work. The text still comes out with the helvetica font.

This is what I changed it to:

f.textfont = font.Times;

Any suggestions as to how I can change the font?

Thanks.
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi carisima,

This is a common problem with copying code. Typos are not uncommon in code copied into these forums, so it really would serve you well to get and use the Acrobat JavaScript Reference. If you look up field properties in the Acrobat JavaScript Reference it you'll see it should be f.textFont ( the F is capitalised). A simple one letter change should make that code work for you and if you look you'll see that in the first post it was capped and then not in the second.

Hope this helps,

Dimitri
WindJack Solutions
www.pdfscripting.com
www.windjack.com
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
All users of the above code should be aware that it for U.S. Letter (8.5 x 11 inches) page with no rotation. If the page is of a different size or pages are rotated, you will have to adjust for those changes.

For larger files, one might want to turn off the automatic calculation for the PDF before adding the fields and then turn it back on exiting from the field creation loop.

George Kaiser

carisima
Registered: Apr 25 2008
Posts: 21
Thanks for the reference and the note. I do use both the reference and the guide. Since I'm not a programmer, I'm still trying to understand the codings I read. It's still a bit confusing to me.

I changed the code, and it works now.

Again, thanks much for the help.
carisima
Registered: Apr 25 2008
Posts: 21
I did notice the page number stays in the same place even for my landscape pages. Since the pages are few, I'll move them manually. I don't know enough about coding to make the rotation adjustment.

About the automatic calculation, can you please explain or point me to some reference? I don't understand your comment.

Thanks much.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
All objects in a PDF are located by "quads" of a series of four numbers that describe the positron of the corners of the object in an unrotated page. Thom Parker has written [url=http://www.acrobatusers.com/tutorials/2007/10/auto_placement_annotations]Automating Placement of Annotations[/url] that explains the coordinates and rotated spaces and how to use the undocumented "Matrix2D" object to obtain the rotated page space and adjust an annotation's or field's quads for placement by JavaScript.

Automatic calculation for placement would be obtaining the crop quads of the page and using the placement offsets for locating the field on the page.

George Kaiser

carisima
Registered: Apr 25 2008
Posts: 21
Thanks for the link to the article. It's a little bit over my head, so I'll take some time to digest and try it before trying to make any changes to what's working for now.