[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Adobe Writer 7 and Security errors

Posted on 2005-04-15
11
Medium Priority
?
1,403 Views
Last Modified: 2011-09-20
Hi All

I am trying to upgrade a script that worked in version 5 of adobe writer but does not want to work in 7 standard.

The script basically just inserts a signature and a date at the end of the document and then I want to do a save as to a directory on the local machine or possible a mapped drive.

I have tried using trustedActiveDocs = app.trustedFunction to make this work along with trusted from propagator but have had no luck. I have downloaded the adobe js books but for a newbie like myself these are not well made.

Anyway here is my script and the error will follow.
-------------------------------------------------
// begin JavaScript
//added to make this a truseted function
trustedActiveDocs = app.trustedFunction (
//start original code
function addSignature()
{
     var lastPage = this.numPages - 1;
     var todaysDateStr = util.printd("mmmm d, yyyy", new Date());
     try
     {
          var dateFieldExists = false;
          var fDateSigned1 = this.getField("dateText");
          if (fDateSigned1.name == "dateText")
          {
               dateFieldExists = true;
          };
     }
     catch(e)
     {
          console.println("\n field dateText does not exist, field will be added");
     };

     if (dateFieldExists)
     {
          var fDateSigned = this.getField("dateText");
     }
     else
     {
          var fDateSigned = this.addField("dateText", "text", lastPage, [30,30,115,48]);
     };

     fDateSigned.defaultValue = todaysDateStr;
     fDateSigned.fillColor = color.white;
     fDateSigned.textColor = color.red;
     fDateSigned.textSize = 0;
     fDateSigned.alignment = "left";
     this.resetForm(fDateSigned);

     try
     {
          var signatureButtonExists = false;
          var fSignatureButton1 = this.getField("signatureButton");
          if (fSignatureButton1.name == "signatureButton")
          {
               signatureButtonExists = true;
          };
     }
     catch(e)
     {
          console.println("\n Button signatureButton does not exist, button will be added");
     };

     try
     {
          if (signatureButtonExists)
          {
               var fSignatureButton = this.getField("signatureButton");
          }
          else
          {
               var fSignatureButton = this.addField("signatureButton", "button", lastPage, [240, 30, 528, 140]);
          };

          fSignatureButton.buttonPosition = position.iconOnly;
          var returnCode = fSignatureButton.buttonImportIcon("c:\\test-eastern.pdf", 0);
          fSignatureButton.buttonScaleWhen = scaleWhen.always;
          fSignatureButton.buttonScaleHow = scaleHow.proportional;
     }
     catch(e)
     {
          app.alert(e);
          console.println("\n Exception while trying to access signatureButton: " + returnCode);
     };

     this.resetForm(fSignatureButton);
      var newDir = "/C/Approved/";
      var name = this.path;
      var pos = name.lastIndexOf("/");
      var newFileName = newDir + name.substring(pos+1, name.length);
      // does the name end with ".pdf"?
      if (newFileName.lastIndexOf(".pdf") != (newFileName.length - 4))
{
    newFileName += ".pdf";
}
console.println("Saving file as " + newFileName);
app.beginPriv();
this.saveAs(newFileName);
app.endPriv();
}



)
//original code
function initializeCreateSignature_2()
{
     // add the menu item
     app.addMenuItem({
          cName: "JSCreateSigMenu",
          cUser: "Add &Eastern Signature",
          cParent: "File",
          cExec: "addSignature()",
          cEnable: "event.rc = (event.target != null);",
          nPos: 0,
     });
}

initializeCreateSignature_2();

// end JavaScript
-------------------------------------------------


ERROR that I am now getting:
-------------------------------------------------
field dateText does not exist, field will be added

 Button signatureButton does not exist, button will be added
Saving file as C:\Approved\AcroJSGuide.pdf

NotAllowedError: Security settings prevent access to this property or method.
Global.saveAs:83:Menu JSCreateSigMenu:Exec
-------------------------------------------------

thanks
mld4165
0
Comment
Question by:mld4165
  • 6
  • 5
11 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 13794680
How do you start the script? (e.g. from a menu item, from a button in the file,...)
0
 
LVL 1

Author Comment

by:mld4165
ID: 13795654
hi khkremer

it is from a menu item.

this part of the code generates the menu item:
function initializeCreateSignature_2()
{
     // add the menu item
     app.addMenuItem({
          cName: "JSCreateSigMenu",
          cUser: "Add &Eastern Signature",
          cParent: "File",
          cExec: "addSignature()",
          cEnable: "event.rc = (event.target != null);",
          nPos: 0,
     });
}

thanks
mld4165
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 13797062
Open up the Acrobat "Preferences" and select the "JavaScript" category. Here you will find the "Enable menu items JavaScript execution privileges" setting. I suspect that this is not checked. Once you select this setting, all your JavaScript menu functions should be executed with more  privileges. Once you do this, you will no longer need the "trustedFunction()"
0
Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

 
LVL 1

Author Comment

by:mld4165
ID: 13803112
in version 7 under Edit --> Preferences there is no setting like this that I could find.

could I be looking in the wrong place?

under trusted documents and javascript everything is enabled.

mld4165
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 13803137
Interesting, this setting does not seem to be available with the "Standard" edition. It's there with Pro. I'll have to do some research to find out how this can be done with Standard (which unfortunately I don't have access to).
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 13805563
OK, I finally looked at your code and found a few problems. I rewrote portions of it (and simplified it in the process). Once this was done, the "trusted" function did work as expected:

// begin JavaScript
//added to make this a truseted function
trustedActiveDocs = app.trustedFunction (
//start original code
function addSignature()
{
     var lastPage = this.numPages - 1;
     var todaysDateStr = util.printd("mmmm d, yyyy", new Date());
     var dateFieldExists = false;
     var fDateSigned = this.getField("dateText");

     if (fDateSigned == null)
     {
          console.println("\n field dateText does not exist, field will be added");
          fDateSigned = this.addField("dateText", "text", lastPage, [30,30,115,48]);
     };

     fDateSigned.defaultValue = todaysDateStr;
     fDateSigned.fillColor = color.white;
     fDateSigned.textColor = color.red;
     fDateSigned.textSize = 0;
     fDateSigned.alignment = "left";
     this.resetForm(fDateSigned);

 
     var fSignatureButton = this.getField("signatureButton");
     if (fSignatureButton == null)
     {
          console.println("\n Button signatureButton does not exist, button will be added");
          fSignatureButton = this.addField("signatureButton", "button", lastPage, [240, 30, 528, 140]);
     }

     fSignatureButton.buttonPosition = position.iconOnly;
     var returnCode = fSignatureButton.buttonImportIcon("c:\\test-eastern.pdf", 0);
     fSignatureButton.buttonScaleWhen = scaleWhen.always;
     fSignatureButton.buttonScaleHow = scaleHow.proportional;

     this.resetForm(fSignatureButton);
     var newDir = "/C/Approved/";
     var name = this.path;
     var pos = name.lastIndexOf("/");
     var newFileName = newDir + name.substring(pos+1, name.length);
     // does the name end with ".pdf"?
     if (newFileName.lastIndexOf(".pdf") != (newFileName.length - 4))
     {
          newFileName += ".pdf";
     }
     console.println("Saving file as " + newFileName);
     app.beginPriv();
     this.saveAs(newFileName);
     app.endPriv();
}



)
//original code
function initializeCreateSignature_2()
{
     // add the menu item
     app.addMenuItem({
          cName: "JSCreateSigMenu",
          cUser: "Add &Eastern Signature",
          cParent: "File",
          cExec: "trustedActiveDocs ()",
          cEnable: "event.rc = (event.target != null);",
          nPos: 0,
     });
}

initializeCreateSignature_2();

0
 
LVL 1

Author Comment

by:mld4165
ID: 13805750
sweet

but seems like their is always one last thing.

seems the date and signature remain in the original document also. could that be changed?

for example the user has a template file they may need to use over and over again.

thanks
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 2000 total points
ID: 13805814
What exactly do you mean by "remain in the original document"?

When you open a template and run your function, the template file is modified and then "saved as" under a new file name. After the "Save As" operation, your open document is no longer linked to the original template, it's now linked to the new file. So, if you modify the file again and save it, the file in the "Approved" directory will be updated.

You can try this when you start with a blank page. Save this as e.g. c:\temp\template.pdf, then apply your signature. Close the document and open c:\temp\template.pdf again. You should not see any form fields in this document.
0
 
LVL 1

Author Comment

by:mld4165
ID: 13806305
oops my bad. I see.

looks like I need to award some points. :-)

Can the javascript check for a filename? I noticed that it seems to pull a temp file name if it does not have one. Since you answered the original question don't feel obligated to answer this one, because I could start another question with new points if needed?

thnaks
mld4165
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 13806372
What do you mean by "check for a filename"? A PDF file open in Acrobat always has a filename (either a temporary name, because you just created the file, or a "real" name because the file was opened , or already saved to the disk).

You could probably check for file names that look like temporary names (e.g. in your temp directory, and start with "Acr"). If you find such a name, you could then prompt the user to specify a file name.

If you want more information about how to do that, you should probably create a new question. Not so much because I need more points, but because if somebody is searching the database for a similar problem, they may not look at this question, because it talks about security. A new question with an appropriate subject line may help somebody to find this information in the future.
0
 
LVL 1

Author Comment

by:mld4165
ID: 13807018
i started a new thread for finding file name:
http://www.experts-exchange.com/Web/Graphics/Adobe_Acrobat/Q_21392825.html

only 250 points but i can award more if it gets complex.

mld4165
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to perform batch conversion of PDF, TIFF, and other image file formats into PDF, PDF Searchable, and TIFF files via a command line interface, using Nuance's latest document imaging software — Power PDF Advanced.
This article focuses on how to remove password security from multiple PDF files by Adobe Acrobat program. Sometimes it is essential to access the stored data items and to print, edit as well as copy content from Portable Document Format files in abs…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question