Annotation import bug

Hi,


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.bindPdf("/Users/mpala/Desktop/result.pdf");
editor.importAnnotationFromXfdf(new FileInputStream("/Users/mpala/Desktop/result-1.xfdf"));
editor.save("/Users/mpala/Desktop/result-2.pdf");
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.

JAVA

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));
lineAnnot.setColor(Color.getRed());
lineAnnot.setStartingStyle(LineEnding.OpenArrow);
lineAnnot.setEndingStyle(LineEnding.OpenArrow);
lineAnnot.setContents("133mm");
lineAnnot.setShowCaption(true);
lineAnnot.setCaptionPosition(CaptionPosition.Top);
asposePage.getAnnotations().add(lineAnnot);
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.

JAVA

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.setColor(com.aspose.pdf.Color.getRed());

lineAnnot.setStartingStyle(LineEnding.OpenArrow);

lineAnnot.setEndingStyle(LineEnding.OpenArrow);

lineAnnot.setContents(“133mm”);


lineAnnot.setMeasure(new Measure(lineAnnot));

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

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

lineAnnot.getMeasure().getDistanceFormat().get_Item(1).setUnitLabel(“mm”);

lineAnnot.getMeasure().getDistanceFormat().get_Item(1).setFractionSeparator(".");

lineAnnot.getMeasure().getDistanceFormat().get_Item(1).setConvresionFactor(1);

lineAnnot.setShowCaption(true);


lineAnnot.setCaptionPosition(CaptionPosition.Top);

asposePage.getAnnotations().add(lineAnnot);

doc.save(dataDir+“lineannotation.pdf”);

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.
(2)