5 Replies Latest reply on Jun 14, 2008 5:23 AM by (David_W._Grimes)

    Saving PDF on blur

      Currently I am working on a project to fill a PDF form inside a C# application. After the form is prefilled the user can fill in the other fields using Adobe Reader embedded inside a Windows Form before signing the document. Originally I used a save button on the pdf with the trusted function to save the pdf. However i would like the user to not have to use the save button and for the document to save itself.

      I tried using the On Blur event of the text fields to trigger the save function which worked until AxAcroPDF object is disposed. As soon as the object is disposed the pdf deletes itself. I'm assuming this is a security feature, because it only happens if the On Blur save event is the last event before disposing the Adobe Reader object. In other words if the cursor was in a text field when the c# button is pressed both events occur simultaneously. I tried putting a time delay thinking it might have been trying to save the pdf while closing, but this didn't work. It works fine if you go from a text field that has this event to another text field which doesn't and then press the c# button. I would appreciate confirmation if this is a security thing or if i just messed something up.

      My work around was to save the document when it was signed which is working, and i clear the signature field with an on blur event from any other text field, which forces the user to resign and saves the pdf. Is it possible to detect a text modification so that the signature is only cleared if the text in the field was changed instead of clearing it anytime the cursor leaves the field?

      Any other suggestions on how to programatically save the document inside of Reader would be appreciated.

      OnBlur javascript:
      var guid = this.getField("GUID");
      var filepath = this.getField("filepath");
      savepath = "filepath + "/" + guid.value + "/" + "doc.pdf";
      mySaveAs(this, savepath);

      Trusted Function:
      mySaveAs = app.trustedFunction
      (
      function(doc, savepath)
      {
      app.beginPriv();
      try
      {doc.saveAs(savepath);}
      catch (err)
      {console.println("Error: " + err);}
      app.endPriv();
      }
      )

      Thanks,
      Mike Kozak
        • 1. Re: Saving PDF on blur
          Patrick Leckey Level 3
          You say your app is using Reader. Is the form Reader Enabled? Otherwise it will not permit a save from Reader.
          • 2. Re: Saving PDF on blur
            Level 1
            Yes it is Reader Enabled, it saves the document fine unless the onBlur event is triggered last.
            • 3. Re: Saving PDF on blur
              I was looking for saveAs help when I came across this discussion. I'm currently figuring out how to set up a save button with a trusted function. I'm really interested in your onBlur event that clears the signature also. I'm really new at this JS game, so any help you would be willing to share would be greatly appreciated. Thanks.
              • 4. Re: Saving PDF on blur
                Level 1
                David, the trusted function mySaveAs.js needs to be placed inside the folder C:\Program Files\Adobe\Reader 8.0\Reader\Javascripts of the pc in which the pdf document will be used. The onBlur event of the cursor leaving a textbox will call the trusted function and pass it the filepath to save the pdf document. If the path does not exist the catch brings up a saveAs dialog box. Hope this helps.
                • 5. Re: Saving PDF on blur
                  Level 1
                  It did...thank you much. I was also wondering about this part:

                  "i clear the signature field with an on blur event from any other text field, which forces the user to resign and saves the pdf. "

                  Did you have to add the onBlur event that clears the signature field to each individual sig field, or did you set it up as some kind of document level script? I'm trying to set-up something to change all fields to read-only after the sig is applied, since it does not seem possible to flatten when the user only has Reader.

                  I'll probably find what I need with a little RTFM (I laugh every time when I read that on the planet forum), but just thought I would ask. Thanks.