4 Replies Latest reply on Aug 19, 2014 1:42 AM by [Jongware]

    Import image using JS (preferred on document-level)




      I am going to implement a dynamic legend using JavaScript in Adobe Acrobat. The document contains a lot of layers. Every layer has an own legend. The origin idea is to implement the legend so, that it contains the images in a dialog box for the visible layers. I can only hide/show the layers by setting state to false or true (this.getOCGs()[i].state = false;) on document-level.


      Question 1: Can I extract data from layer somehow  for legend establishing? I think no, as we only have these function on layers: getIntent(), setIntent() and  setAction(). Right? Therefore I decided to arrange it so, that all needed icons for every layer are saved in a folder with corresponding names. JavaScript should import the icons and I build the a dialog window with icons of visible Layers and place a text(description for this icon).


      I tried all possibilities of image import described here: http://pubhelper.blogspot.com.au/2012/07/astuces-toolbar-icons-et-javascript.html. I got only one way (Convert the icons as hexadecimal strings). This way isn't good, as it is too much work to create with an other tool a hexadecimal string from a images and place it into a javascript code.

      Unfortunately, I cannot import image using other methods:(. Since the security settings in Adobe are changed after version 7 or so, it is not possible to use functions like app.newDoc, app.openDoc, even app.getPath On document-level. I decided to implement the import on the folder level using trusted functions like this:


      Variant 1:

      var importImg = app.trustedFunction(function() {


          var myDoc = app.newDoc({

              nWidth: 20,

              nHeight: 20


              var img = myDoc.importIcon("icon", "/icon.png", 0);


          return img;


      var oIcon = importImg();

      NotAllowedError: Security settings prevent access to this property or method.



      Variant 2:

      var importImg = app.trustedFunction(function() {

             var appPath = var phPath = app.getPath({

              cCategory: "user",

              cFolder: "javascript"


             try {


              var doc = app.openDoc({

                  cPath: phPath + "/icon.png",

                  bHidden: true



          } catch (e) {

              console.println("Could not open icon file: " + e);



              var oIcon = util.iconStreamFromIcon(doc.getIcon("icon"));

          return oIcon;


      var oIcon = importImg();


      Error: Could not open icon file: NotAllowedError: Security settings prevent access to this property or method.

      The settings in Preferences->JavaScript-> JavaScript Security are disabled (Enable menu item JS execution privileges, enable global object security policy).

      Question 2: Is it not allowed or should I change some other settings or use the import on any other way?


      I tried all these possibilities with .jpg, .png, .pdf. with different sizes(big images and 20x20 pxls), It doesn't work.

      Could somebody help me, as I spent a lot of time with trying different possibilities. It would be actually better to implement the main goal described above on document level, are there other possibilities to access images, maybe using xml or something else) (Question 3)?


      Thank you and kind regards,