• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Can't delete custom document info

Explorer ,
Jan 16, 2018 Jan 16, 2018

Copy link to clipboard

Copied

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?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

646

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 16, 2018 Jan 16, 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 Metada

...

Votes

Translate

Translate
Community Expert ,
Jan 16, 2018 Jan 16, 2018

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 16, 2018 Jan 16, 2018

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 16, 2018 Jan 16, 2018

Copy link to clipboard

Copied

LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines