3 Replies Latest reply on Jan 16, 2018 7:13 PM by Thom Parker

    Can't delete custom document info

    cschmelter Level 1

      If I open a PDF that has no custom meta data under document.info, I can add a new meta data entry by running the following code in the console:

       

      this.info.foo = "bar";

       

      If I then save the document the "foo" meta data entry persists. However, if I try to delete the meta data entry by running the following code in the console:

       

       

      this.info.foo = null;

       

      Right after running this code to delete the meta data entry, if I look in Document properties the entry no longer shows. However, as soon as I hit Save the "foo" meta data entry shows up again. It seems there's no way to persist the removal of metadata entries.

       

      Is there something I'm doing wrong?

        • 1. Re: Can't delete custom document info
          Thom Parker Adobe Community Professional

          The correct way to remove a property is to delete it

           

          delete this.info.foo;

           

          Unfortunately that doesn't work either.

          The info data is tricky.  Back way when, it really was the document metadata. But that hasn't been true for a while. Now it's just a convenience. The real metadata is stored as XML in the "doc.metadata" property.  If you delete an "info" property, or set it to null, it only changes the "info". It doesn't change the XML metadata. You can  see and edit the XML from the "Additional Metadata" button on the "Description" tab of the document properties dialog.  Editing the metadata really does change things.

           

          I'm sure this is a bug. The "info" property is supposed to edit the XML, and it does when setting a property. It should work the same for deleting a property.

          • 2. Re: Can't delete custom document info
            cschmelter Level 1

            Thanks for the response. I initially tried doing:

             

            delete this.info.foo;

             

            but that didn't even remove the property before saving whereas setting it to null at least removing it and made it persist until saved. Ok yes, it sure sounds like a bug. Since you said the "info" property is more of a convenience, is there a way for me to set meta data in JavaScript another way?

            • 3. Re: Can't delete custom document info
              Thom Parker Adobe Community Professional

              Yes, the meta data is just an XML string and it can be set. But it's tricky, it has to be done in the right way or Acrobat will choke and ignore the change.

               

              There is an example, and an explanation of how to do it correctly in the doc.metadata entry in the Acrobat JavaScript Reference, here:

              Acrobat DC SDK Documentation

              1 person found this helpful