Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active October 18, 2021 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/b8061ef7e09f811300992f5e29b18a27 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/b8061ef7e09f811300992f5e29b18a27 to your computer and use it in GitHub Desktop.
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