Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Highlight and Links Annotations to Annotate PDF documents using Java
// Create Hyperlinks in PDF using link annotations in Java
Annotator annotator = new Annotator("path/sample.pdf");
List<Point> points = new ArrayList<Point>();
points.add(new Point(120, 300));
points.add(new Point(600, 300));
points.add(new Point(120, 270));
points.add(new Point(600, 270));
LinkAnnotation link = new LinkAnnotation();
link.setCreatedOn(Calendar.getInstance().getTime());
link.setPageNumber(0);
link.setPoints(points);
link.setUrl("https://products.groupdocs.com/annotation");
annotator.add(link);
annotator.save("path/annotation-link.pdf");
annotator.dispose();
// Highlight PDF using highlight annotation in Java
Annotator annotator = new Annotator("path/sample.pdf");
List<Point> points = new ArrayList<Point>();
points.add(new Point(120, 270));
points.add(new Point(600, 270));
points.add(new Point(120, 300));
points.add(new Point(600, 300));
HighlightAnnotation highlight = new HighlightAnnotation();
highlight.setBackgroundColor(0xFFF000);
highlight.setOpacity(0.5);
highlight.setPageNumber(0);
highlight.setPoints(points);
annotator.add(highlight);
annotator.save("path/annotation-highlight.pdf");
annotator.dispose();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment