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

Help for Set PDF metadata from Acrobat JavaScript

Community Beginner ,
Oct 10, 2022 Oct 10, 2022

Hello dera friends,

in the published post `Get and Set PDF metadata from Acrobat JavaScript` by Mr. Thom Parker (https://acrobatusers.com/tutorials/get-and-set-pdf-metadata-from-acrobat-javascript/) is code for changing `Custom properties` in Acrobat. The JS code is: this.info.mySpecialProp = 3; // Create a custom entry

 

I'm wondering how to add a DOT in the code above? Namely, if I want to use a code with a dot like `this.info.mySpecial.Prop = 3; (where DOT is present in custom name aka mySpecial.Prop)` this JS code does not work with the ActionWizard function. Can someone help me to solve the problem? Thanks in advance for your reply and any suggestion.

 

BR Aljoša

TOPICS
Edit and convert PDFs , How to , JavaScript
2.7K
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
1 ACCEPTED SOLUTION
Community Expert ,
Oct 10, 2022 Oct 10, 2022

As with most JS properties, you can do it if you access the property name as a string, instead of a variable name.

So use this instead:

this.info["mySpecial.Prop"] = 3;

The result:

try67_0-1665390637491.png

You'll also need to access it the same way later on, though.

 

View solution in original post

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 ,
Oct 10, 2022 Oct 10, 2022

The info object is accessed by properties that are JavaScript names. You cannot use a dot in a name. So, this seems impossible; I suggest you rethink your plans. 

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 ,
Oct 10, 2022 Oct 10, 2022

As you can see the dot is used as a separator, so you cannot use it in a custom metadata name.


Acrobate du PDF, InDesigner et Photoshopographe
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 ,
Oct 10, 2022 Oct 10, 2022

Hi there and thanks JR Boulay and Test Screen Name...I kown that but I also needed confirmation from any of you by`those who know more' that there is no trick/hack that I could use...unfortunately, I need a DOT because of the requirements of the agencies and because we have a lot of these kinds of documents...well...I will correct the change of record with Notepad++ (its time consuming, but I will satisfy the agencys requirements according to the record in `custom properties`).  I wish you a nice and pleasant day. Regards Aljosa

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 ,
Oct 10, 2022 Oct 10, 2022

As with most JS properties, you can do it if you access the property name as a string, instead of a variable name.

So use this instead:

this.info["mySpecial.Prop"] = 3;

The result:

try67_0-1665390637491.png

You'll also need to access it the same way later on, though.

 

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 ,
Oct 10, 2022 Oct 10, 2022

That's a neat trick! Thank you.

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 ,
Oct 10, 2022 Oct 10, 2022

OMG !!!...try67 you are a GENIUS...I can't believe IT WORKS..I already tried it myself but apparently wrong (I put a dot in brackets (aka [.] and ["."] but it didn't work) .Now it works like magic. If you will ever been nearby Slovenia I'll take you for a beer right away ..or a seven...THANK YOU VERY MUCH. Regards from here. Aljosa

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 ,
Oct 10, 2022 Oct 10, 2022

You're welcome! But seven beers is a bit much for me... Let's settle on three and a hot-dog! 🙂

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 ,
Oct 10, 2022 Oct 10, 2022

Slovenian beers are famous!


Acrobate du PDF, InDesigner et Photoshopographe
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 ,
Oct 10, 2022 Oct 10, 2022

My dear try67 ... I mean it...you have done us a very big favor..and don't worry...I will arrange all those beers with food...and transportation for a safe trip home too...I am beyond grateful and on behalf of everyone...THANK YOU BECAUSE WE HAVE YOU. BR Aljosa

 

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 ,
Oct 10, 2023 Oct 10, 2023

Is there a way to include letters with accents in the metadata name.  When I try this as above, it creates the name but excludes any accented letters.  Example:  this.info["ÄBC"]=123 creates name BC, value 123

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 ,
Oct 10, 2023 Oct 10, 2023

It might work if you edited the metadata XML string directly. Apply the value manually and then examine it like this via the JS Console:

this.metadata

You'll see it appears as a tag towards the end of the string:

 

try67_0-1696946850546.png

 

So to add it using a script you would need to read the file's metadata property, edit it, and then re-apply it.

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 ,
Oct 10, 2023 Oct 10, 2023

That worked.  Thank you.  I can't do anything manually.  It's all automation.  I'm going to have to replace each possible accent letter with another value, then rewrite the metadata, replacing those values back:

this.metadata=this.metadata.replace(/-A-/g,"Ä")

There's (*almost*) always a way.  Thanks again.

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 ,
Oct 10, 2023 Oct 10, 2023

This isn't exactly what I meant, but that works too, I guess!

And the manual part was just to see how it needs to appear in the metadata XML string. You do it manually so you know how to automate it later on.

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 ,
Oct 10, 2023 Oct 10, 2023

What you suggested did not work for me, but this did:

 

this.info["xxxAxxxBC"] = "123";
this.metadata=this.metadata.replace(/xxxAxxx/g,"\u00C4")
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 ,
Oct 10, 2023 Oct 10, 2023

Correct.  I used "\xC4" instead of "\u00C4".  Is there a script that you know of that converts characters to the  ASCII or unicode values?  Thanks again.

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 ,
Oct 10, 2023 Oct 10, 2023
LATEST

The best way is to Google it: "Ä unicode"

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