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

Adding object metadata to dynamic stamp

Community Beginner ,
Jun 23, 2023 Jun 23, 2023

Copy link to clipboard

Copied

Hello all, 

 

I am creating a custom dynamic stamp for a project. 

 

The Support Community's archives have been of much help as I have been working. Thank you.

I have already worked out the main functionality (auto-increment, cf. https://community.adobe.com/t5/acrobat-sdk-discussions/dynamic-stamp-with-an-incremental-number/m-p/...) of the stamp.

 

The stamp is to be used several times in the same document, and its content is different every time it is stamped (the content of the stamp is based on the number of said stamps in the document).

 

For each occurrence of the stamp in a document, I would like to track its dynamic content and the page number on which the stamp occurs. 

 

My first approach was to track these data in a JS Array and then save the ‘stringified’ array to the PDF's metadata. 

 

The problem with this, however, is that if a stamp is deleted from the document, it does not delete the corresponding item in the JS Array. Because of this, the metadata in the PDF does not accurately track all the stamps present in the final saved document. 

 

The ability to add metadata at the object, i.e. the stamp, level (https://helpx.adobe.com/acrobat/using/pdf-properties-metadata.html) would solve this problem. If I were to delete an object, the corresponding metadata would be deleted. The sum of all the object metadata would accurately track all the stamps present in the final saved document. 

 

I am not sure whether it is possible to implement adding metadata to a stamp object, and, if it is, I do not know how it would be done. I tried event.source.info (on analogy with event.source.source.info), but the debugger console threw out an error.

 

If it is not possible, I would welcome other approaches, such as creating a script that would alter the JS Array upon the deletion (either outright or through Ctrl-Z) of a stamp.

 

[moderator corrected a typing mistake as of OPs follow-up post.]

TOPICS
Acrobat SDK and JavaScript , Mac

Views

1.4K

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 , Jun 23, 2023 Jun 23, 2023

At the save event you can delete the entries in the array of all not existing stamps.

Votes

Translate

Translate
Community Beginner ,
Jun 23, 2023 Jun 23, 2023

Copy link to clipboard

Copied

In the original post, "For each occurrence of the stamp in a comment" should read "For each occurrence of the stamp in a document"

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 ,
Jun 23, 2023 Jun 23, 2023

Copy link to clipboard

Copied

At the save event you can delete the entries in the array of all not existing stamps.

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 Beginner ,
Jun 27, 2023 Jun 27, 2023

Copy link to clipboard

Copied

Guten Tag Herr Alheit, 

 

vielen Dank für Ihre schnelle Antwort. 

 

Ich habe noch eine Frage. Wie könnte ich vergleichen die Geschichte in meinem Array mit der endlichen Zeichnung von getAnnots()? 

 

Bei getAnnots(), nennt die Eigenschaft ".name" jede Annotation einzigartig. Ich habe versucht, diese Eigenschaft in meinem Array zu legen. Aber weil ich schreibe mein Array in derselben "Script" in der das "event.value" vom "Dynamic Stamp" berechnet wird, kann das neueste getAnnots() Array nicht gerufen wird (das letzliche "Stamp", d.h. das "Stamp" dessen "event.value" derzeitig berechnet wird, fehlt immer). 

 

Kann ich eine andere "Script" machen, die legt die annot.name Eigenschaft in mein Array so bald wie die Berechnung-Script fertig ist? Oder gibt es eine andere Weise, alles in der Berechnung-Script zu machen?

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 Beginner ,
Jul 27, 2023 Jul 27, 2023

Copy link to clipboard

Copied

LATEST

I have marked this as the correct answer because it pointed me in the direction of my eventual solution. While I was neither able, as proposed in the question, to add metadata to the stamp object nor able, as proposed elsewhere, to access the annotation name within the stamp caluclation script, I was able, using a save script, to gather enough information about the final saved state of the PDF such that I could generate from that information along with the array an accurate list of each stamp and the page on which it occurs. 

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 ,
Jun 28, 2023 Jun 28, 2023

Copy link to clipboard

Copied

"My first approach was to track these data in a JS Array and then save the ‘stringified’ array to the PDF's metadata. "

 

What data does store in the array?

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 Beginner ,
Jun 28, 2023 Jun 28, 2023

Copy link to clipboard

Copied

The event.value and the page number on which the stamp is placed. The event.value is usually unique, but can repeat. The page number is, naturally, determined by the user. Neither of these is enough to uniquely identify a given stamp. 

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 ,
Jun 28, 2023 Jun 28, 2023

Copy link to clipboard

Copied

Annotations (which stamps are) don't have events, or values. They do have various properties, though, and one of them is the name property, which is a unique ID (if you let the application apply it, and don't specify it manually). You can use it to identify and access an annotation, along with its page number.

A typical name value is something like this "1c901f39-8ca9-4ada-9d4a-90d3bdd541f8".

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 Beginner ,
Jun 28, 2023 Jun 28, 2023

Copy link to clipboard

Copied

Yes, I think this will need to be part of my solution. My trouble is that I cannot access the "annotation name" when the calculation script is running, which is where I am making the array of stamp information that I am storing to the metadata. 

 

Your suggestion that I can manually change the annotation name is promising. If I could make custom names in accordance with a regular method, then I could add those same names to the array made in the calculation script, and then have a means by which to compare the array made in the calculation scripts (i.e., all stamps ever stamped) to the array in getAnnots() (i.e., all stamps present at document save). I do not, however, know how to change the annotation name manually, or programatically.

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 ,
Jun 28, 2023 Jun 28, 2023

Copy link to clipboard

Copied

You need to get a reference to the Annotation object (how you do that depends on when you want this code to run), and then simply change its name property.

For example, this code will change the name of the first annotation on page 1 to "Annot1Page1":

this.getAnnots({nPage: 0})[0].name = "Annot1Page1";

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 Beginner ,
Jun 28, 2023 Jun 28, 2023

Copy link to clipboard

Copied

Perfect, thank you for that.

 

Is there a way to change that annotation name while the calculation script for the dynamic stamp is being run? My past attempts to access the getAnnots() array from the calculation script have failed because the most recent stamp (i.e. the stamp for which the event.value is being calculated) was always missing. 

 

If that it is not possible, is there a way to change the annotation name as soon as the calculation script finishes, or (to put it another way) immediately after the stamp has been placed onto the page. The goal would be to change the name before the user is able to delete the stamp. 

 

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 ,
Jun 28, 2023 Jun 28, 2023

Copy link to clipboard

Copied

No, because at that moment the stamp doesn't exist yet, so getAnnots will not return it.

The only way that might work (I haven't tested it) is to run the code with a delay (using setTimeOut). The newly created annotation should be the last one in the array returned by getAnnots.

Or you can do it when the file is saved (you'll need to embed a script in it for that, though).

 

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 Beginner ,
Jun 28, 2023 Jun 28, 2023

Copy link to clipboard

Copied

Thank you, that is what I assumed. 

 

And, to confirm, there is also no way to set a script (e.g., one that would change the name property of the latest stamp) to run every time after a stamp has been placed?

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 ,
Jun 28, 2023 Jun 28, 2023

Copy link to clipboard

Copied

Not automatically, no. In theory it could be done using a script that runs on an interval, but this can cause the file to seriously slow down and even the application to freeze. I would not recommend it.

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 Beginner ,
Jun 28, 2023 Jun 28, 2023

Copy link to clipboard

Copied

Ok. Thank you for your help. My original problem remains unresolved, though.

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