Embedded JS - Adobe Document Javascripts

It is possible to use the class Core.Annotations.Forms.EmbeddedJS to define or overwrite functions from Adobe Document Javascripts? If possible, is there an example of this?

1 Like

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

1 Like

Hello l.l.serrala,

Welcome to the PDFTron Community Forum.

You can access the Adobe scope (ADBE) within a document, using:

Annotations.Forms.EmbeddedJS.update(scope => {
  // Scope represents the window scope that embedded javascript runs within
  // Define the ADBE namespace so that older PDFs will find it
  scope.ADBE = {};
});

You can read more here: https://www.pdftron.com/documentation/web/guides/forms/embedded-js/#customization

Best Regards,
Tyler Gordon
Web Development Support Engineer
PDFTron Systems, Inc.
www.pdftron.com

1 Like

Thank you for your answer, but I’ve seen this example / guide before. I ask because I don’t understand how to use it to define or override a function from Adobe Document Javascripts. We are using some PDFs with the same document javascript functions, now there is a change for a function so we would like to try declaring this function directly in the viewer instead of having to change a lot of PDFs.

1 Like

Hello l.l.serrala,

Would you be able to provide a sample document for me to create a specialized code snippet for an example?

In general, you would override a function in the EmbeddedJS like this:

    Annotations.Forms.EmbeddedJS.update((scope) => {
     // Where .Test is a custom function defined in the PDF
      scope.Test = () => {
        console.log("Test function")
      }
    });

Best Regards,
Tyler Gordon
Web Development Support Engineer
PDFTron Systems, Inc.
www.pdftron.com

1 Like

how do I add a new function through EmbeddedJS?
also, my new function content is coming inside a var.
for eg: var custom=“if(global){do something…}”
how do i embed this piece inside?

1 Like