3 Replies Latest reply: Apr 2, 2012 7:42 AM by Eldrarak82 RSS

    How to tell if a change was made to a PDF by a plugin before saving?

    Eldrarak82

      I have a plugin which I have written which is executed via COM by my C#.net 4.0 launcher application. The function of the plugin is to scan the opened PDF for any annotations that are "Launch" annotations, and to update them to either JS actions or to URI actions.

      The problem is that some of the documents which will be passed into the plugin do NOT have annotations in them, and so the plugin code is written to do nothing to the documents in this case.

      The documents which are modified by the plugin will be saved to location on the local hard drive, however the files that are not edited are simply to be moved to a different location.

       

      How can my COM application tell if the opened PDF has been modified by the plugin before saving or copying the file?

       

      I was thinking that if I could get an MD5 or a byte array of the temp file which is created by Acrobat as soon as the document is opened, and compare it to the MD5 or byte array of the same temp file after the changes have (or have not) been made to the document, then I would be able to tell if a change had occured. Is this the best way to go about this? Is there a better way?

       

      If the temp file is my best bet, is there any way for my COM application to know the name of the temp file when it is created?

      Just looking for some ideas or suggestions on how best to tell if the file has been changed or not, before saving it.

        • 1. Re: How to tell if a change was made to a PDF by a plugin before saving?
          BarlaeDC Community Member

          Hi,

           

          As you are using com and C# you could use the JSObject and check the doc.dirty property and this would tell you if the file needed saved.

           

          The documentation for the Doc.dirty property is in the JavaScript Guide included in the SDK.

           

          Hope this helps

           

          Malcolm

          • 2. Re: How to tell if a change was made to a PDF by a plugin before saving?
            Eldrarak82 Community Member

            Thanks Malcolm, let me take a look at the docs and give that a try

            • 3. Re: How to tell if a change was made to a PDF by a plugin before saving?
              Eldrarak82 Community Member

              Okay thanks Malcolm. That did the trick. I will say that in C#, it is a little bit of a chore to get those JS commands to execute correctly, so I will post the code here that worked for anyone else who has this issue and needs the resolution.

               

                      private static bool TestDirty(AcroAVDocClass avDoc, AcroPDDoc pdDoc)
                      {
                          object jso = pdDoc.GetJSObject();
                          bool docDirty = false;

                          try
                          {
                              if (jso != null)
                              {
                                  string[] fileToOpenArr = new string[1] { fileToOpen };
                                  object jsApp = jso.GetType().InvokeMember("app", BindingFlags.GetProperty, null, jso, null, null);

                                  if (jsApp != null)
                                  {
                                      object jsDocs = jsApp.GetType().InvokeMember("activeDocs", BindingFlags.GetProperty, null, jsApp, null, null);

                                      if (jsDocs != null)
                                      {
                                          object[] arrObj = (object[])jsDocs;
                                          object theJSDoc = arrObj[0];

                                          object objDirty = theJSDoc.GetType().InvokeMember("dirty", BindingFlags.GetProperty, null, theJSDoc, null, null);
                                          docDirty = Boolean.Parse(objDirty.ToString());
                                      }
                                  }
                              }
                          }
                          catch
                          {
                              //Catch thh exception
                          }

                          return docDirty;
                      }