0 Replies Latest reply on Jun 23, 2009 7:37 AM by bryanribas123

    importDataObject Extend features in reader security issue help. Code inside

    bryanribas123

      Okay here is my issue. This code work 100% as a javascrip button for acrobat. I looks for the file name and does a saveas in a directory and appends a txt file with the data from the PDF form. The only issue I have is when I save the PDF to extend the features in adobe reader, I can no longer use importDataObject. I get a security error. I think it is ebacuse it will not allow me to add anything to the pdf because it is save with securty. If I use it on another pdf that does not have the extended features it works with out an issue.

       

       

       

      ////////////////////////////////////////////////////
      ////// Save As & export as text ///////
      ////// Created By: Bryan Ribas  //////
      ////// Nutmeg Finacial M.H.C.   //////
      //////////////////////////////////////////////////


      app.addToolButton({
      cName: "myToolButton",   
      cExec: "trustedNewDoc()",    ///// Function exicuted on click
      cTooltext: "Send To ViewIt", ///// Text when mouse hover
      cLabel: "Process to ViewIt", ///// Name on Button

      });

       

      trustedNewDoc = app.trustedFunction( function () ////Raise the permisions
      {

      app.beginPriv();
      try {

       

      //// Global Variables
      docname = this.documentFileName;
      docname = docname.replace(".pdf", "");
      systime = new Date();
      day = systime.getDay();
      month = systime.getMonth();
      year = systime.getFullYear();
      hour = systime.getHours();
      minutes = systime.getMinutes();
      seconds = systime.getMilliseconds();
      randomnumber = Math.floor(Math.random()*101);
      randomnumber2 = Math.floor(Math.random()*101);
      randomfinal = Math.round((seconds + 1) * randomnumber2)*randomnumber;
      currentDate = month + "_" + day + "_" + year;

       

      /////MY ISSUE IS HERE.

      var myDoc = event.target;
      myDoc.importDataObject("BusinessVisaCheckCardApplication.txt", "BusinessVisaCheckCardApplication.txt");
      oFile = this.getDataObjectContents("BusinessVisaCheckCardApplication.txt");
      xlsfile = util.stringFromStream(oFile, "utf-8");

       

       

      ///// Check File Name
      if((docname.search("BusinessVisaCheckCardApplication")==0))
      {

       

      /// get the fields
      var AdminEntry = this.getField("AdminEntry").value;
      var AdminVerify    = this.getField("AdminVerify").value;
      var AreaCode = this.getField("AreaCode").value;
      var BranchManagerApproval = this.getField("BranchManagerApproval").value;
      var BusinessName = this.getField("BusinessName").value;
      var BusinessAddress = this.getField("BusinessAddress").value;
      var BusinessTIN = this.getField("BusinessTIN").value;
      var BranchManagerApproval = this.getField("BranchManagerApproval").value;
      var CIS = this.getField("CIS").value;
      var CMSEntry = this.getField("CMSEntry").value;
      var CMSVerify = this.getField("CMSVerify").value;
      var CardHolderName = this.getField("CardHolderName").value;
      var Checking = this.getField("Checking").value;
      var CityStateZip = this.getField("CityStateZip").value;
      var DDAProductType = this.getField("DDAProductType").value;
      var DateOpened = this.getField("DateOpened").value;
      var EmployeeOffice = this.getField("EmployeeOffice").value;
      var Offset = this.getField("Offset").value;
      var Owner = this.getField("Owner").value;
      var PAN = this.getField("PAN").value;
      var PhoneNumber = this.getField("PhoneNumber").value;
      var Savings = this.getField("Savings").value;

       

      //issues start here again

      // append current data to the end, using tabs to separate info
      var xlsfile = xlsfile + "\r\n" + AdminEntry + "\t" + AdminVerify + "\t" + AreaCode + "\t" + BranchManagerApproval + "\t" + BusinessName+ "\t" + BusinessAddress + "\t" + BusinessTIN + "\t" + CIS + "\t" + CMSEntry  + "\t" + CMSVerify  + "\t" + CardHolderName  + "\t" + Checking  + "\t" + CityStateZip  + "\t" + DDAProductType  + "\t" + Date + "\t" + DateOpened + "\t" + Offset + "\t" + Owner + "\t" + PAN + "\t" + PhoneNumber + "\t" + Savings;

      //convert back to a file stream
      var oFile = util.streamFromString(xlsfile, "uft-8");

      // now "overwrite" BusinessVisaCheckCardApplication.xls
      this.setDataObjectContents("BusinessVisaCheckCardApplication.txt", oFile);

       

       

      ////Export and Save As Actions THIS ALL WORKS
      this.saveAs ("\\\\#$%#^\\IVM_Data\\load\\"+ docname + "_" + BusinessTIN + "_" + currentDate + "_"+ randomfinal +".pdf"); ///Saves form in folder as PDF
      this.exportAsText({cPath: "\\\\**$#@%^n\\IVM_Data\\Data\\"+ docname + "_" + randomfinal + ".txt"});  //////////Exports the data out of the form to a txt
      }

       

       

      ///// Template To Add Another Form To Process
      else if ((docname.search("NewPDFFormName")==0))
        {

      app.alert(xlsfile); // Pop up window

        }

       

      ////// If The Form Name Does Not Match Any Name In The Above If Statements
      else{

      app.alert("This form is has already been processed or is not eligable to process."); // Pop up window

      }}

       

      //////// On Error Function
      catch (err) {

       

      app.alert("An error has accured: \n\nA paper copy of this form is printing.\nPlease be sure to interoffice it to the correct department.\n\nMore info: " + err); ////Error Pop up windown

       

      /////Print Hard Copy
      var pp = this.getPrintParams();
      pp.interactive = pp.constants.interactionLevel.automatic; /// Set to Automatic for no user interaction
      pp.printerName = "HP LaserJet 4250 PCL 6"; ///Set Printer Name
      this.print(pp);  ///Prints

       

      }
      app.endPriv(); //end program

       

      })