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

Free Support Forum - aspose.com

Annotation import bug


I’m trying to import the XFDF annotations into a PDF, but the import fails with the exception below. Source files attached. The XFDF file was created using the same PdfAnnotationEditor class with exportAnnotationsXfdf from a different PDF.

PdfAnnotationEditor editor = new PdfAnnotationEditor();
editor.importAnnotationFromXfdf(new FileInputStream("/Users/mpala/Desktop/result-1.xfdf"));
class com.aspose.pdf.internal.ms.System.z9: An element with the same key already exists in the dictionary.
com.aspose.pdf.internal.ms.System.Collections.Generic.z2.addItem(Unknown Source)
com.aspose.pdf.XfdfReader.m1(Unknown Source)
com.aspose.pdf.StampAnnotation.m1(Unknown Source)
com.aspose.pdf.XfdfReader.m1(Unknown Source)
com.aspose.pdf.XfdfReader.readAnnotations(Unknown Source)
com.aspose.pdf.facades.PdfAnnotationEditor.m2(Unknown Source)
com.aspose.pdf.facades.PdfAnnotationEditor.importAnnotationFromXfdf(Unknown Source)

Hi Mariusz,

Thanks for contacting support.

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Arial; -webkit-text-stroke: #000000} span.s1 {font-kerning: none}

I have tested the scenario and have managed to reproduce the problem that while importing your provided xfdf file into your result.pdf document it throws an exception. For the sake of correction, I have logged it as PDFJAVA-36557 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction.

Please be patient and spare us little time. We are sorry for this inconvenience.

Best Regards,

OK, thanks. Can you also share some sample code to create linedimension and polygondimension annotation? Thank you!

Hi Mariusz,

Thanks for your inquiry. Please see following sample code for line and polygon Annotations. I have also attached the generated PDF document for your reference.


String dataDir = “/Users/fahadadeel/Downloads/resources/”;
Document doc = new Document();
Page asposePage = doc.getPages().add();
Rectangle location = new Rectangle(100, 100, 600, 600);
LineAnnotation lineAnnot = new LineAnnotation(asposePage, location, new Point(200, 200), new Point(400, 400));
Page asposePage1 = doc.getPages().add();
// Add annotation
double left = 100f;
double top = 100f; double right = 200f; double bottom = 200f;
PolygonAnnotation polyAnnotation = new PolygonAnnotation( asposePage1, new Rectangle(left, top, right, bottom), new Point[]{ new Point(left, top), new Point(right, top), new Point(right, bottom), new Point(left, bottom) } );

polyAnnotation.setColor(Color.getBlue()); polyAnnotation.setInteriorColor(Color.getRed()); Border border = new Border(polyAnnotation); border.setWidth(3); polyAnnotation.setBorder(border);
polyAnnotation.setContents("Contents"); polyAnnotation.setReplyType(ReplyType.Reply); polyAnnotation.setTitle("Title"); asposePage1.getAnnotations().add(polyAnnotation);

doc.save(dataDir + "linenpolyannotation1.pdf");

If you still face any issue, please feel free to contact us.

Best Regards,

Hi Fahad

this is incorrect. the OP requested a line dimension and polygon dimension annotation

not line and polygon annotation.

when the annotation is resized, the measurement should be recalculated.

thank you

Hi Mariusz,

Thanks for additional information.

We have already logged a ticket PDFJAVA-36326 that LineAnnotation and PolyLineAnnotation created with measure settings are not being recalculate upon resize. I have linked your query with the issue ID. We will keep you posted on the status of correction. Please be patient and spare us little time.

Moreover, below is the sample code for your reference.


Document doc= new Document();

com.aspose.pdf.Page asposePage=doc.getPages().add();

com.aspose.pdf.Rectangle location=new com.aspose.pdf.Rectangle(100,100,600,600);

LineAnnotation lineAnnot = new LineAnnotation(asposePage, location, new Point(200,200), new Point(400,400));





lineAnnot.setMeasure(new Measure(lineAnnot));

lineAnnot.getMeasure().setDistanceFormat(new Measure.NumberFormatList(lineAnnot.getMeasure()));

lineAnnot.getMeasure().getDistanceFormat().add(new Measure.NumberFormat(lineAnnot.getMeasure()));








We are sorry for the inconvenience.

Best Regards,
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Arial; -webkit-text-stroke: #000000} span.s1 {font-kerning: none}

The issues you have found earlier (filed as PDFJAVA-36557) have been fixed in Aspose.Pdf for Java 17.3.0 Release Notes.

This message was posted using Notification2Forum from Downloads module by Aspose Notifier.