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

Add and modify the XMP data in Acrobat DC using javascript

Contributor ,
Apr 07, 2022 Apr 07, 2022

Hi All,

Is it possible to modify the meta data in the PDF file acrobat DC using Javascript?

 

Screenshot 2022-04-07 at 11.53.27 PM.pngexpand image

 

Thanks

 

TOPICS
JavaScript
2.1K
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 ,
Apr 07, 2022 Apr 07, 2022

Yes. The metadata property of the Document object gives you direct r/w access to the raw XMP data, as a string.

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
Contributor ,
Apr 08, 2022 Apr 08, 2022

Is it possible to add/modify via Javascript/Applescript?

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 ,
Apr 08, 2022 Apr 08, 2022

Yes, as I wrote.

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
Contributor ,
Apr 08, 2022 Apr 08, 2022

Could you please share some samples how to modify the XMP data. Im new to this which is really helpful

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
Contributor ,
Apr 08, 2022 Apr 08, 2022

Im trying with below shell script it doesn't change the XMP data

do shell script exiftoolPath & " -Keywords=" & quoted form of newMetadataValue & space & imagePath
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 ,
Apr 08, 2022 Apr 08, 2022

To do that you can use the info property, like this:

 

this.info.Keywords = "Text";

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 ,
Apr 08, 2022 Apr 08, 2022

It's just a string. You can modify it using the various methods available in JS for text manipulation.

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
Contributor ,
Apr 08, 2022 Apr 08, 2022

Im trying to change year 2021 to 2022 but it not works...

this.info.Year = "2022"

Screenshot 2022-04-08 at 2.11.05 PM.pngexpand image

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
LEGEND ,
Apr 08, 2022 Apr 08, 2022

Only a few elements are available via Info, these are the PDF metadata which existed before XMP. Author, Keywords, Subject, Title. Changing these fields also automatically updates the XMP. In other cases you have to edit the XML - this is not a simple task.  

 

But the one example you are using is not JavaScript, it is shell script, and is not using Acrobat at all, but an EXIF tool. The JavaScript we are talking about is the internal Acrobat JavaScript, which you cannot run from the command line. Run it from the Acrobat JavaScript console.

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
Contributor ,
Apr 08, 2022 Apr 08, 2022

Thank for the info!

Im tried with the below shell script but it changes the value for CreateDate, CreatorTool and it doesn't the value for year

property exiftoolPath : "/usr/local/bin/exiftool"

set newMetadataValue to "2022"
set imagePath to quoted form of (POSIX path of (choose file of type "pdf"))

-- Add new metadata "Keywords"
do shell script exiftoolPath & " -Year=" & quoted form of newMetadataValue & space & imagePath



Screenshot 2022-04-08 at 2.11.05 PM.pngexpand image

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
LEGEND ,
Apr 08, 2022 Apr 08, 2022

The subject you posted was "Add and modify the XMP data in Acrobat DC using javascript" but this isn't JavaScript and isn't Acrobat DC.

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
Contributor ,
Apr 08, 2022 Apr 08, 2022
LATEST

FYI I have tried in different soruces also for that only I have shared the shell script here.

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