Re-Usage of Javascript-Snippets / subroutines?

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Peter2
User
Posts: 948
Joined: Mon Sep 13, 2010 10:09 am
Location: Switzerland

Re-Usage of Javascript-Snippets / subroutines?

Post by Peter2 »

Under "Document-Properties" there is a feature where I can manage named JS snippets:
grafik.png
I wonder if these "snippets" could be re-used under "Javascript actions" of form-fields?

Simple Example:
I have fields with values a, b and c.

- I want to create a button which read these fields and check if they are valid.
- Then I need a button which calculates something with these values: a plus b minus c ..
- Finally I need a button which takes the values, creates a filename and save the file

So the beginning of these codes are always the same - read and store the data of a, b and c.

In other code I would create and call "subroutines". is it possible here?

Have a fine weekend and thanks for your great support!
You do not have the required permissions to view the files attached to this post.
PDF-X-Change Pro German
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3556
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada

Re: Re-Usage of Javascript-Snippets / subroutines?

Post by Ivan - Tracker Software »

Yes, and that's the main purpose of document-level 'snippets'.
The code of these snippets is executed on the document open.
You can define a function in this document-level code, and use this function in field action handlers.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
Peter2
User
Posts: 948
Joined: Mon Sep 13, 2010 10:09 am
Location: Switzerland

Re: Re-Usage of Javascript-Snippets / subroutines?

Post by Peter2 »

Thanks, Ivan
Ivan - Tracker Software wrote: Fri Feb 17, 2023 11:02 pm ...You can define a function in this document-level code, and use this function in field action handlers....
Is there an example for this?

BTW:
Are there some downloads for the user which demonstrate different / special / sophisticated features of the software and the PDF-format?
PDF-X-Change Pro German
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: Re-Usage of Javascript-Snippets / subroutines?

Post by Tracker Supp-Stefan »

Hello Peter2,

The "function" referred to above is this:
https://developer.mozilla.org/en-US/doc ... /Functions

You declare it with a name and input parameters, and then there is code inside of it that takes the input, processes it in some way and returns to you some output. You can then call this function from various places in your document.

We do not have JS specific tutorials, but this might also be of good use:
=https://opensource.adobe.com/dc-acroba ... Reference

Kind regards,
Stefan
Peter2
User
Posts: 948
Joined: Mon Sep 13, 2010 10:09 am
Location: Switzerland

Re: Re-Usage of Javascript-Snippets / subroutines?

Post by Peter2 »

Thanks Stefan, OK for me.
PDF-X-Change Pro German
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re-Usage of Javascript-Snippets / subroutines?

Post by Tracker Supp-Stefan »

:)