Highlighted

Button Creation Location

Community Beginner ,
Aug 21, 2020

Copy link to clipboard

Copied

I've figured out a way to automate button creation, but it continues to be placed at the bottom left of the page. I've used multiple approaches, one of which was this: https://acrobatusers.com/tutorials/js_add_buttons_to_pdf/

 

var pgRect = this.getPageBox("Crop", nPage);
	var fldRect = []; 
fldRect [0] = pgRect[0] + 36; fldRect [1] = pgRect[0] + 56; fldRect [2] = pgRect[0] + 72; fldRect [3] = pgRect[0] + 36; var oFld = this.addField( cName , "button", nPage, fldRect);

 

I adjusted the numbers and tried to move it to the top left corner (I've since deleted it so I forgot which numbers I used exactly). However, no matter what I do the button size itself is the only thing that's changing and staying in the left corner. How can I hit my "Create button" button and have it place the new button on the top of the page instead of the bottom left? Is this possible?

Topics

Create PDFs, Edit and convert PDFs, General troubleshooting, How to, PDF forms

Views

27

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Button Creation Location

Community Beginner ,
Aug 21, 2020

Copy link to clipboard

Copied

I've figured out a way to automate button creation, but it continues to be placed at the bottom left of the page. I've used multiple approaches, one of which was this: https://acrobatusers.com/tutorials/js_add_buttons_to_pdf/

 

var pgRect = this.getPageBox("Crop", nPage);
	var fldRect = []; 
fldRect [0] = pgRect[0] + 36; fldRect [1] = pgRect[0] + 56; fldRect [2] = pgRect[0] + 72; fldRect [3] = pgRect[0] + 36; var oFld = this.addField( cName , "button", nPage, fldRect);

 

I adjusted the numbers and tried to move it to the top left corner (I've since deleted it so I forgot which numbers I used exactly). However, no matter what I do the button size itself is the only thing that's changing and staying in the left corner. How can I hit my "Create button" button and have it place the new button on the top of the page instead of the bottom left? Is this possible?

Topics

Create PDFs, Edit and convert PDFs, General troubleshooting, How to, PDF forms

Views

28

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 21, 2020 0
ls_rbls LATEST
Adobe Community Professional ,
Aug 22, 2020

Copy link to clipboard

Copied

You missed another important tutorials about this topic.

 

The one you're using is a little more advanced and without understanding the basics it doesn't make sense to jump straight into document-level scripting.

 

See here: 

 

 

Folowing  Thom Parker's turorial on finding page boundaries and PDF page geometry, I was able to figure out how to anchor a an mouse-up action button field to the left upper corner of the page.

 

This is my very first time learning this stuff. I suggest you take a moment and read Thom Parker's guides. They're always excellent (in my opinion) and extremely helpful and resourceful.

 

This is what worked for me:

 

var fldRect = this.getPageBox("Crop",this.pageNum); 

fldRect[0] -= -36; // 1/2 from left Side 
fldRect[1] -= 36; // 1/2 inch from top side 
fldRect[2] -=  436; //  Adjust Right Side
fldRect[3] = rFld[1] -36; // Adjust Bottom Side

 

 

Just remember, that when you work with a parent object (like a button filed in this case), the child objects are broken down in an array that follows a strict order using a zero-based index.

 

In other words, the first page in  a PDF document will always start at "0", not Page 1.

 

And when you work with checkboxes  in a mutually exclusive fashion (for example, four fields with the same parent name but each with a different export value), it would be expressed like this:

 

var f = this.getField("myCheckBox");
f.checkThisBox(0)  <<<--- first checkbox
f.checkThisBox(1)
f.checkThisBox(2)
f.checkThisBox(3)

 

Another example , when you work with words, and you're trying to figure out how to identify the 3rd letter in that word it whould be expressed as : 

 

f.charAt(0)

f.charAt(1)

f.charAt(2)   <<<-------- thrid letter

f.charAt(3)

 

So, in the case of a Crop box, the zero-based index logic is:

 

var fldRect = this.getPageBox("Crop", this.pageNum);   <<<---- for the current page you're working on

fldRect[0] =  Adjust from Left Side
fldRect[1] =  Adjust from Top Side
fldRect[2] =  Adjust Right Side
fldRect[3] =  Adjust Bottom Side

 

 

 

 

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 22, 2020 0