Skip to main content
Participating Frequently
June 23, 2023
Answered

Adding object metadata to dynamic stamp

  • June 23, 2023
  • 3 replies
  • 2363 views

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/8223946) 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.]

This topic has been closed for replies.
Correct answer Bernd Alheit

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

3 replies

Bernd Alheit
Community Expert
Community Expert
June 28, 2023

"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?

Participating Frequently
June 28, 2023

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. 

try67
Community Expert
Community Expert
June 28, 2023

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".

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
June 24, 2023

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

Participating Frequently
June 27, 2023

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?

Participating Frequently
June 23, 2023

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