Skip to main content
Participant
January 29, 2016
Question

Triggering an action with mousedown

  • January 29, 2016
  • 3 replies
  • 1261 views

I'm working on a single page pdf that includes a large number of buttons. I have been trying to write a script that will export a text file containing only the name of the button clicked. I'm going to embed the script in each button and use the mousedown event to trigger it.

I'm experiencing two problems:

  1. When I test run the script without having it embedded in the button (and using a text string to define the button name), the script executes properly and creates a text file containing the string. However, when I try to trigger the action with mousedown I get an error telling me that my document output variable isn't properly defined.
  2. Every time I open the pdf I need to re-initiate the script, before it can be run from the buttons. Is there a way to configure it so that it will be pre-loaded when opened?

Thanks in advance. I'm sorry about how vague my questions are, but I don't have access to acrobat at the moment.

This topic has been closed for replies.

3 replies

Inspiring
January 29, 2016

It is possible when using the JavaScript console to introduce new variables or functions that remain persistent until all the currently open PDFs are closed or Acrobat/Reader is closed. This will cause a PDF form or script that works fail the next time Acrobat/Reader is opened.

Karl Heinz  Kremer
Community Expert
Community Expert
January 29, 2016

You should have all the information you need to fix the problem based on the error message. Something is not available when it's required.

As to initializing the script when the document is opened: Create a document level script (call it e.g. "initialization"). When the editor comes up, it will have a function stub in it. Remove that and add your initialization code. Document level scripts are executed when the file is opened. You may also want to consider putting your code that you need to execute in every button into a document level function and then only call that function from each button - with a parameter that indicates what button was pressed. The "event" object does contain that information. You can e.g. pass event.target.name to the function and then have the button name available in your document level function.

Bernd Alheit
Community Expert
Community Expert
January 29, 2016

We can't help without seeing the script.