Skip to main content
Inspiring
January 16, 2018
Answered

Can't delete custom document info

  • January 16, 2018
  • 1 reply
  • 1065 views

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?

This topic has been closed for replies.
Correct answer Thom Parker

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.

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
January 17, 2018

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.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
January 17, 2018

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?

Thom Parker
Community Expert
Community Expert
January 17, 2018

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

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often