Javascript trigger actions for form fields created using WebViewer

Hi,

How to set the trigger actions for form fields created using WebViewer formbuilder UI?

For eg: if a text field is created in an interactive form using PDFTron WebViewer UI, is it possible to configure a javascript function / code as an action for calculate trigger, format trigger or a keystroke trigger through WebViewer?
I am currently evaluating WebViewer version 5.2.8

Thanks,

Syed

Hello Syed,

Sorry for the late response! I have responded to your StackOverflow question but I will repeat it here as well!

You will have to create the UI components yourself that will take in the JavaScript code. You can do something similar to what the FormBuilder demo does with just HTML and JavaScript. However, it may be better to clone the open-source UI and add your own components.

As for setting the action, I would recommend trying out version 6.0 instead as there is better support for widgets and form fields in that version. However, we are investigating a bug with the field actions that will throw an error on downloading the document. You should be able to use this code to get it working first:

    docViewer.on('annotationsLoaded', () => {
      const annotations = annotManager.getAnnotationsList();
      annotations.forEach(annot => {
        const action = new instance.Actions.JavaScript({ javascript: 'alert("Hello World!")' });
        // C cor Calculate, and F for Format
        annot.addAction('K', action);
      });
    });

Once the bug has been dealt with, you should be able to download the document properly.

Otherwise, you will have to use the full API and that may be less than ideal. It would be a bit more complicated with the full API and I would not recommend it if the above feature will be fixed soon.

Let me know if this helps or if you need more information about using the full API to accomplish this!

Andy Huang

Software Developer
PDFTron Systems Inc.

Thanks very much for the response.
I will certainly try version 6.0 as well.
I would like to understand about using the full api for setting the javascript trigger actions and downloading the document, so that we can use it until the download issue gets resolved. I would also like you to help me in figuring out setting the javascript trigger actions for an existing fillable form using java and javascript api.
Let me know if this needs to posted as a separate question.

Hi Syed,

Sorry for the late response!

I have provided the solution to your question on StackOverflow: https://stackoverflow.com/questions/59564649/javascript-trigger-action-for-form-fields-created-using-pdftron-webviewer-formbu/

You can just give a reply there instead of here. I do want to mention that a fix could be available next week. Once it is available, you will not need the full API code to fix the download issue. All that will be left is for you to design the UI components to allow inserting the JavaScript actions.

Andy Huang

Software Developer
PDFTron Systems Inc.