Forum How do I...?

Is it possible to generate a unique annotation for separated content?

ns426
Hello,

I'm working with PDF annotations using PrinceXML version 15.4.1, and I was wondering if it is possible to generate a single annotation for content that is located in separate nodes. I tried using ids, but two different annotations are generated:

#comment {
  -prince-pdf-annotation-type: text;
  -prince-pdf-annotation-contents: 'Are you sure?';
}

<body>
  <p>
    This is just
    <span id="comment"> a comment </span>
  </p>
  <p><span id="comment"> with some random </span> content</p>
</body>


Is there any way to generate a unique annotation?

Thanks in advance!
mikeday
We don't have a mechanism to create one annotation from two elements; how exactly would you want that to look like in the PDF?
ns426
We have an application that allows arbitrary text selections, so for example given this list:

<ul>
  <li>
    <p>My item1 with content</p>
  </li>
  <li>
    <p>My item2 with content</p>
  </li>
</ul>


It may happen that the content to which the comment is applied is "with content My item2". In such cases, I want to display only a single comment for that selection. The result that I expect in the generated PDF is the one from the attached image
  1. Screenshot 2025-04-01 at 10.49.46.png29.2 kB
mikeday
Right, I will add this to the development roadmap.
mikeday
In the Prince pre-release builds we have added a new property:

prince-pdf-annotation-merge: none | duplicates | key(<string>)

The -prince-pdf-annotation-merge property has the following possible values, which affects the creation of user annotations on the same page.

Each user annotation with '-prince-pdf-annotation-merge: none' is considered distinct.

For user annotations with '-prince-pdf-annotation-merge: duplicates', all annotations that would be generated on the same page, with the same type, author, title, contents, creation/modification date, color and icon, will be "merged", resulting in only one annotation in the PDF. Note that icon position is ignored.

For user annotations with '-prince-pdf-annotation-merge: key(<string>)', all annotations that would be generated on the same page, that have the same key, will be "merged", resulting in only one annotation in the PDF.