4 Replies Latest reply on Jun 22, 2016 1:42 AM by try67

    Trusted function for app.newDoc always returns undefined

    MikeIs2C Level 1

      Hi,

       

      I am trying to make a button-activated script.  Its purpose is to save a copy of the first page (clearing any form data) to its own file saved in the same path as the open document.  As part of that I needed to create a trusted function to cover privileges for the app.newDoc function.  I have the following:

       

      trustedNewDoc = app.trustedFunction( function (nWidth, nHeight)

      {

          app.beginPriv();

          app.newDoc( nWidth, nHeight );

          app.endPriv();

      });

       

      This has been saved in a file called "newdoc.js" in the javascript "app" folder.  I closed Acrobat Pro XI and restarted it.  As soon as I try to activate a button with just: "var myDoc = trustedNewDoc(500,500);", it opens the document as specified, but I get "undefined" returned for myDoc -- which prevents further handling. 

       

      If I run the same line from the console it also returns undefined.  Running "var myDoc = app.newDoc();" also returns undefined, but just "app.newDoc();" alone returns "[object Doc]" -- although "trustedNewDoc(500,500);" alone is still undefined.

       

      Anyway, I feel like I am missing something fundamental, even though I have found guides suggesting to do exactly what I have implemeted.  I am pretty much sure I have entered everything correctly and followed all steps, so at this point I am stumped.  Any help would be greatly appreciated!

       

      Thanks,

       

      Mike

        • 1. Re: Trusted function for app.newDoc always returns undefined
          try67 MVP & Adobe Community Professional

          You need to return the doc object from within your trusted function, like so:

           

          trustedNewDoc = app.trustedFunction( function (nWidth, nHeight)

          {

              app.beginPriv();

              var doc = app.newDoc( nWidth, nHeight );

              app.endPriv();

              return doc;

          });

          • 2. Re: Trusted function for app.newDoc always returns undefined
            MikeIs2C Level 1

            Thank you Gilad, that was exactly what was needed!  And thank you for getting back to me so quickly.  Now I really wish I would have asked this question earlier yesterday after spending hours trying to find a solution.

             

            Unfortunately there really weren't any examples I found where a value was being returned.  Perhaps it is common sense and I should have known better, but I thought the value was being returned through other means.  Anyway, it is working great thanks to your help!  Now I have a separate issue I need to see if I can get help with. Hey, great work and thanks again! 

            • 3. Re: Trusted function for app.newDoc always returns undefined
              rajavardhanr3623689

              same issue m facing when i try to access "app.newDoc()",Displaying Error: Security settings prevent access to this property or method.

              even I unchecked protected mode in secuity(enhanced) category in also javascript settings  enabled all javascript debugger.
              app.newDoc() is placed in trusted function ,even we are using this.disclosed=true property also.Please anyone can help out

               

              code in brief

              PPDF_trustedNewDoc = app.trustedFunction(function() {

                  try{

                     // console.println("PATHSS::"app.getPath("app", "javascript"));

                      app.beginPriv();

                  console.println("New Doc: "+app.newDoc());

                newDoc = app.newDoc();

                newDoc.addScript("init", "this.disclosed=true");

                app.endPriv();

                return newDoc;

                  }

                  catch(err){

                      console.println("Error: "+err.message);

                  }

               

              });

               

              Thanks in advance

              • 4. Re: Trusted function for app.newDoc always returns undefined
                try67 MVP & Adobe Community Professional

                Please don't post the same question in multiple locations.