We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to remove field annotation

We have form field with multiple annotations, and need to remove just few of them and keep others. When trying to remove annotation directly from collection we get java.lang.UnsupportedOperationException


Sample code attached

Hi John,


Thanks for your inquiry. We can remove the Field Annotation as following but I am afraid it removes all annotations of the field. So I have logged a ticket PDFJAVA-36068 in our issue tracking system to remove a specific field annotation. We will notify you as soon as it is resolved.

…<o:p></o:p>

.....

if (field.size() > 0) {

{

@SuppressWarnings("unchecked")

Iterator iterator = field.iterator();

int i=1;

while (iterator.hasNext()) {

Annotation annot = iterator.next();

System.out.println("field annotation " + annot.getFullName()+" Position: "+annot.getRect()+" field count:"+i);

// iterator.remove();

if (i==2)

pdf.getForm().delete(annot.getFullName());

i++;

}

}

.....

.....


We are sorry for the inconvenience.

Best Regards,

Any progress on this ?

Hi John,


Thanks for your inquiry. I am afraid above reported issue is still not resolved, it is pending for investigation as currently our product team is busy in resolving other issues in the queue. We will notify you as soon as we made some significant progress towards issue resolution.

We are sorry for the inconvenience.

Best Regards,

Hi John,


Thanks for your patience.

We have further investigated earlier reported PDFJAVA-36068 and have found that you can delete the specific annotation after creation and reload the document.

First you need to remove following lines from your code snippet to create the sample:

if (i==2)
pdf.getForm().delete(annot.getFullName());

Then use the the following snippet to delete one of the annotations.

[Java]

Document pdf = new Document(myDir

  • “formoutput.pdf”);<o:p></o:p>

    System.out.println(pdf.getPages().get_Item(1).getAnnotations().size());<o:p></o:p>

    <o:p></o:p>

    for (Annotation a: (Iterable)pdf.getPages().get_Item(1).getAnnotations())<o:p></o:p>

    {<o:p></o:p>


    System.out.println(a.getRect());<o:p></o:p>


    //Delete
    the specific annotation
    <o:p></o:p>


    if (new Rectangle(150, 0,
    250, 100).equals(a.getRect())) <o:p></o:p>


    pdf.getPages().get_Item(1).getAnnotations().delete(a);<o:p></o:p>

    }
    <o:p></o:p>

pdf.save(myDir + “formoutput2.pdf”);