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

How do I add custom properties with JavaScript in Adobe DC?

Community Beginner ,
Aug 01, 2017 Aug 01, 2017

Hi all,

I'm in the process of batch adding metadata to PDF documents in Adobe DC.

My script is working for all the default elements like Title and Subject, but I'd like to be able to add the key value (name, value) pairs for custom properties as well, but I can't figure out how to access the custom properties to write to them.

Can anyone help me out with this?

TOPICS
Acrobat SDK and JavaScript
4.5K
Translate
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 ,
Aug 01, 2017 Aug 01, 2017

Take a look at the JavaScript documentation - especially the Doc.info property: Acrobat DC SDK Documentation

In the examples, you will see how the "ISBN" and "PublishDate" custom properties are added. Keep on mind that this will not work in any script running in the free Adobe Reader.

Translate
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 Beginner ,
Aug 01, 2017 Aug 01, 2017

The SDK Doc has been helpful, but the properties still aren't getting written to file > properties > custom properties.

Translate
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 ,
Aug 01, 2017 Aug 01, 2017

I would recommend to implement this in steps. The first step should be that you manage to set the custom properties for one document, outside of your loop. Take for example these lines and execute them in the JavaScript console:

this.info.Title = "The Title";

this.info.Subject = "The Subject";

this.info.ModDate = "01/02/2017";

this.info.program = "The Program";

this.info.owner = "The Owner";

If you can get this to work, then you can start to debug things in your loop;

Translate
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 Beginner ,
Aug 01, 2017 Aug 01, 2017

Good call!

It's working now.

Thanks!

Translate
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 ,
Aug 01, 2017 Aug 01, 2017

The doc.info object works just like any other JavaScript object; by setting the property, you've created it. For example...

this.info.foo = "bar";

...both creates the metadata field "foo" and sets the value to "bar". Properties can be read in the same way.

Translate
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 Beginner ,
Aug 01, 2017 Aug 01, 2017

Would this then appear in the custom properties section in the document?

Because, so far, I've tried it out and it's not worked.

I've got an array of objects that I'm looping through like this:

var i = 0;

obj.forEach(function() {

    if (this.documentFileName === obj.filename) {

      this.info.Title = obj.title;

      this.info.Subject = obj.subject;

      this.info.ModDate =  obj.datePosted;

      this.info.program = obj.program;

      this.info.owner = obj.owner;

     i++

  };

});

And all the default, Title, Subject, ModDate get moved over perfectly, but the program and owner do not. Do I need to set progam and owner somewhere first?

Cheers,

Translate
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 ,
Aug 01, 2017 Aug 01, 2017

Look under the Custom tab of the Document Properties...

Translate
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 Beginner ,
Aug 01, 2017 Aug 01, 2017

"with JavaScript"

Translate
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 ,
Aug 01, 2017 Aug 01, 2017
LATEST

lcreale  wrote

"with JavaScript"

I understood that... Run the JS code and then check the Custom tab and you'll see that the information is there.

Translate
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