简体   繁体   中英

Reuse javascript in Adobe Acrobat

When creating a form via Adobe LiveCycle Designer, it is possible to create a script object, which will contain all your scripts (functions), so that you'll be able to reuse them in different fields without code duplication. For example, it is possible to create Rules object, which will contain a method

function showTest(){
 console.println("Text is shown");
}

then, if you have two buttons with click actions, you can use this function in both of them without code duplication, like this:

 Rules.showTest();

Is there any way to do the same via Adobe Acrobat Pro? I have a lot of fields, which have the same rule and I don't want to copy my code multiple times.

If I understand the question correctly, this is not how the PDF/Acrobat document object model works.

You can define functions on document level. But you will have to call the function from every active element where it should be used.

I strongly suggest to get the Acrobat Javascript documentation, which is part of the Acrobat SDK, downloadable from the developer section of the Adobe website. You will find all the needed information in the Guide and the Reference document. You should have a good look and (and try to understand) the event handling model.

If you have some reasonable field naming, it is possible to add the above mentioned function call using Javascript, via the Console.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM