Create multi-line highlight annotation in PDF using Java with Aspose.PDF for Java

Hi Aspose,


I’d like to create a pdf like in “pdf-sample_highlighted_by_adobe.pdf”, can you let me know how to do it using setQuadPoints() API? My code below produced “pdf-sample_highlighted_by_aspose.pdf”.

String inputFilePath = “D:\tmp\Tuyen\testPdf\pdf-sample.pdf”;
String outputFilePath = “D:\tmp\Tuyen\testPdf\pdf-sample_highlighted_by_aspose.pdf”;
try (InputStream inStream = new FileInputStream(inputFilePath);
OutputStream outStream = new FileOutputStream(outputFilePath)) {
Document pdfDocument = new Document(inStream);
Page page = pdfDocument.getPages().get_Item(1);
double llx = 85.7114;
double lly = 656.144;
double urx = 509.957;
double ury = 686.697;
Rectangle rect = new Rectangle(llx, lly, urx, ury);
HighlightAnnotation annotation = new HighlightAnnotation(page, rect);
Color color = Color.YELLOW;
annotation.setColor( com.aspose.pdf.Color.fromRgb(color));
annotation.setTitle(“vntun”);
annotation.setSubject(“vntun sub”);
Point[] points = new Point[]{getPoint(201.458, 686.204),
getPoint(505.748, 686.204),
getPoint(201.458, 670.436),
getPoint(505.748, 670.436),
getPoint(89.9206, 672.404),
getPoint(250.49, 672.404),
getPoint(89.9206, 656.636),
getPoint(250.49, 656.636)
};
annotation.setQuadPoints(points);
page.getAnnotations().add(annotation);
pdfDocument.save(outStream);
}

public static Point getPoint(double x, double y) {
return new Point(x, y);
}

Please note that the points data above is from getQuadPoints when I tried to read HighlightAnnotation from “pdf-sample_highlighted_by_adobe.pdf”. I’m using Aspose pdf 17.2.0.

Thank you.

Best Regards,
Tuyen

Hi Tuyen,


Thanks for contacting support.

I have tested the scenario and noticed that HighlightAnnotation is not working as expected with QuadPoints, so logged a ticket PDFJAVA-36685 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

We are sorry for this inconvenience.

Best Regards,

The issues you have found earlier (filed as PDFJAVA-36685) have been fixed in Aspose.Pdf for Java 17.5.


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