Skip to main content
M.Hasanin
Inspiring
November 25, 2017
Question

Restoring Button Position

  • November 25, 2017
  • 1 reply
  • 861 views

Hi...

i changed some buttons position using (.rect) function, so the buttons is controlled with other buttons to make them go up and down or right and left, are there anyway  to restore the original position for the buttons! that was created first time before moving them ? , thanks for help

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
November 25, 2017

There are a couple of ways.

1. Do not save the PDF. This way the buttons will always be at the position that was last saved.

2. Save a list of original coordinates in a hidden field. Use JSON so it'll be easy to set and get.

On this page ,  Free Sample PDF Files with scripts   , is a list of Sample PDF files, on it you'll find the "Swat the Fly" game, which is basically a button that moves around on the page. It does not solve your problem of saving the original position, its just an interesting sample of the process you've described.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
M.Hasanin
M.HasaninAuthor
Inspiring
November 26, 2017

Thank you,

yes i set a hidden copy of the button in the original position and now its easy to restore it back to its position with JSON, thank you..

i was using lingo (Macromedia Director Coding Language) and i always compare lingo with javascript, things much easier done in lingo and in lingo its easy to restore the rect becuase the software always remember the original rect or you can store it in Global Variable, i wonder if javascript for Acrobat have its own Global Variables or stuff like that will done from Document Level JavaScript,, Thanks for your help.

Mohammad Hasanin
Thom Parker
Community Expert
Community Expert
November 26, 2017

Why yes, there are global variables in Acrobat JavaScript where the original position could be stored. For example, this codes stores a field rectangle into a document level variable. The scope of the variable is the document object, and it's lifetime is the lifetime of the document.

this.SaveRect = this.getField("Button1").rect;

You could also save to the global object.

global.SaveRect = this.getField("Button1").rect;

You can even make global objects persistent across Acrobat sessions.

I suggested a hidden field because it is persistent with the document, which is where the buttons live. If you don't need persistence, then a document level variable is easier than a field.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often