Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Triggering an action with mousedown

New Here ,
Jan 28, 2016 Jan 28, 2016

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.

TOPICS
Acrobat SDK and JavaScript , Windows
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2016 Jan 29, 2016

We can't help without seeing the script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2016 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2016 Jan 29, 2016
LATEST

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.

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