user5342176
user5342176

Reputation: 101

How to add annotations and comments/replies using PDF Box

I am working on highlighting selected area in PDF document using PDFBox API and then adding conversations/replies against the highlight. The PDAnnotationTextMarkup() API is used for highlighting the selected text.

To add the conversations for this highlight, I have created one text annotation i.e PDAnnotationText() and one popup annotation i.e PDAnnotationPopup().

For text annotation, I have set the following attributes.

PDAnnotationText txtAnnot = new PDAnnotationText ();
   txtAnnot.setAnnotationName((UUID.randomUUID().toString()));          
   txtAnnot.setInReplyTo(highlightAnnot); // Reference to highlight annotation       
   txtAnnot.setName(PDAnnotationText.NAME_COMMENT);
   txtAnnot.setCreationDate((new GregorianCalendar()));             
   txtAnnot.setTitlePopup(userName);

For popup annotation, initialized following attributes.

 PDAnnotationPopup popAnnot = new PDAnnotationPopup ();
   popAnnot.setParent(txtAnnot); //Above text annotation

After adding the couple of conversations in the above pattern save the annotations and updated disk file. However, I could see the highlight, but not the added conversations in Acrobat Reader popup menu.

Do I need to set any other attributes to text and popup annotations, such as rectangle dimensions etc) ?

Please help me, if I miss any ste

Thanks in advance. CM

Upvotes: 2

Views: 3631

Answers (2)

Krishna Prasad D
Krishna Prasad D

Reputation: 41

PDAnnotationTextMarkup markup =
      new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
markup.setContents(letterValue);

where letterValue(String Format) is the Value you want on pop-up.

Upvotes: 2

mjmaurer
mjmaurer

Reputation: 51

I had the same problem. I had forgotten to add the annotations to the PDPage using .setAnnotations().

Upvotes: 1

Related Questions