Javascript Limitations and Workarounds

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

Moderators: Daniel - PDF-XChange, PDF-XChange Support, Vasyl - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Post Reply
User avatar
⚜ Kenny Lemens, P.E. ᵂᴵ
User
Posts: 34
Joined: Thu Jan 23, 2025 4:09 pm

Javascript Limitations and Workarounds

Post by ⚜ Kenny Lemens, P.E. ᵂᴵ »

Greetings!

Reviewing the forums, I have notice threads discussing 「App Level Javascripts」 and how they need to be saved to either:
  • 「file:\\C:\Program Files\Tracker Software\PDF Editor\」
  • 「%appdata%\Tracker Software\PDFXEditor\3.0\」
Support of benign scripts is pretty straight forward, but if a person wants global[] variable access, utilize readFileIntoStream(), or to manipulate the 'this' object; those calls must occur within a 「trusted function」, least a user receives the Error:
  • NotAllowedError: Security settings prevent access to this property or method.
However, through my research, it becomes apparent that (even with the use of a 「trusted function」 ) some functions just will not work on the app-level (albeit these functions WILL work on the document level):
  • this.createTemplate()
    • Paul - PDF-XChange wrote: Thu May 26, 2022 9:20 pm Hi pigster,

      this would be because we do not currently support the method createTemplate(). We agree we should, so it will be added. I have raised the associated Support Request and this item will be delivered at the Development Team Leader's discretion.

      Currently I have no ETA for this, but am hopeful it will be in the next scheduled build in a few months time.

      RT#6109: Feature request :: Editor :: add support for JS API createTemplate() is for internal use only, but it is your reference to send us in case you are looking for an update.
  • this.newPage()
    • Stefan - PDF-XChange wrote: Mon Jan 23, 2023 10:15 am Hello nuflux,

      Over the weekend I got some feedback from one of our devs.
      They told me that they will investigate the situation, and it might be a bug on our end that the trustedFunction works with newDoc() but does not work with newPage(). As soon as I have more information I will post again here!

      Kind regards,
      Stefan


    With all that as a backdrop:
    . Are functions this.createTemplate() and this.newPage() still in limbo for App-Level JavaScript? If these functions still are in limbo, are there any workarounds?

    Personally, I was able to find (1) workaround, and that is this.insertPages() is supported. I can either reference the current page of cPath:this.path or reference a blank-PDF to have the effect of this.newPage(). However, I would rather use this.newPage instead of forcing a work-around solution.


    May this be of Good Help;
    ⚜ Kenny Lemens, P.E. ᵂᴵ

    Sources:
    1. How do I add a custom tool to the toolbar, using JavaScript, in the Editor? https://www.pdf-xchange.com/knowledgeba ... the-Editor
    2. How to create custom buttons in Toolbar: viewtopic.php?t=40336
    3. Using Trusted Functions [url]https://www.pdfscripting.com/public/Using-Trusted-Functions.cfm[/url]
    4. EPIC User Created Custom Hatch Pattern Tool (with Trusted Functions, custom dialog box, custom user settings, custom icon, filestream, Global Variables) viewtopic.php?t=40329
    5. Acrobat JavaScript Scripting Reference
      • Adobe Acrobat 7.0.5 [PDF]
        • https://www.pdfill.com/download/AcroJS.pdf
      • Adobe Acrobat 7.0 [PDF]
        • https://experienceleaguecommunities.adobe.com/skucn57933/attachments/skucn57933/adobe-livecycle-community-qanda/101891/1/AcroJS.pdf
      • ONLINE: JavaScript APIs:
        • https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html
User Plugins: https://is.gd/A9HMPG || PDF-XChange Icons: https://is.gd/Z4GeG8
[Migration] Revu Bluebeam 17 to PDF-XChange Editor: https://is.gd/8Xs1OF
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3585
Joined: Thu Jul 08, 2004 10:36 pm
Contact:

Re: Javascript Limitations and Workarounds

Post by Ivan - Tracker Software »

this.createTemplate() is still not implemented.

this.newDoc() requires trusted context. In one of the next builds, we will add an option to add document(s) to the JS-trusted locations.
PDF-XChange Co Ltd. (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.
Post Reply