From d2919b3e4dde6554152b2a22afc7b06c7f59434d Mon Sep 17 00:00:00 2001 From: SemenchenkoA Date: Tue, 29 Aug 2023 11:43:05 +0300 Subject: [PATCH] add examples for annotations --- .../AddImageAnnotation.java | 21 ++++++++ .../AddSearchTextAnnotation.java | 20 ++++++++ .../AddSquigglyAnnotation.java | 48 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 Examples/src/main/java/com/groupdocs/annotation/examples/basic_usage/add_annotation_to_the_document/AddImageAnnotation.java create mode 100644 Examples/src/main/java/com/groupdocs/annotation/examples/basic_usage/add_annotation_to_the_document/AddSearchTextAnnotation.java create mode 100644 Examples/src/main/java/com/groupdocs/annotation/examples/basic_usage/add_annotation_to_the_document/AddSquigglyAnnotation.java diff --git a/Examples/src/main/java/com/groupdocs/annotation/examples/basic_usage/add_annotation_to_the_document/AddImageAnnotation.java b/Examples/src/main/java/com/groupdocs/annotation/examples/basic_usage/add_annotation_to_the_document/AddImageAnnotation.java new file mode 100644 index 0000000..fc90f0e --- /dev/null +++ b/Examples/src/main/java/com/groupdocs/annotation/examples/basic_usage/add_annotation_to_the_document/AddImageAnnotation.java @@ -0,0 +1,21 @@ +package com.groupdocs.annotation.examples.basic_usage.add_annotation_to_the_document; + +import com.groupdocs.annotation.Annotator; +import com.groupdocs.annotation.examples.Constants; +import com.groupdocs.annotation.models.Rectangle; +import com.groupdocs.annotation.models.annotationmodels.ImageAnnotation; + +public class AddImageAnnotation { + public static void run() { + try(final Annotator annotator = new Annotator(Constants.INPUT_PDF)){ + ImageAnnotation imageAnnotation = new ImageAnnotation(); + imageAnnotation.setBox(new Rectangle(100, 100, 100, 100)); + imageAnnotation.setOpacity(0.7); + imageAnnotation.setPageNumber(0); + imageAnnotation.setImagePath("www.google.com.ua/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png"); + imageAnnotation.setAngle(100.); + annotator.add(imageAnnotation); + annotator.save("result_image_annotation.pdf"); + } + } +} diff --git a/Examples/src/main/java/com/groupdocs/annotation/examples/basic_usage/add_annotation_to_the_document/AddSearchTextAnnotation.java b/Examples/src/main/java/com/groupdocs/annotation/examples/basic_usage/add_annotation_to_the_document/AddSearchTextAnnotation.java new file mode 100644 index 0000000..11f69df --- /dev/null +++ b/Examples/src/main/java/com/groupdocs/annotation/examples/basic_usage/add_annotation_to_the_document/AddSearchTextAnnotation.java @@ -0,0 +1,20 @@ +package com.groupdocs.annotation.examples.basic_usage.add_annotation_to_the_document; + +import com.groupdocs.annotation.Annotator; +import com.groupdocs.annotation.examples.Constants; +import com.groupdocs.annotation.models.annotationmodels.SearchTextFragment; + +public class AddSearchTextAnnotation { + public static void run() { + try(final Annotator annotator = new Annotator(Constants.INPUT_PDF)){ + SearchTextFragment searchTextFragment = new SearchTextFragment(); + searchTextFragment.setText("Welcome to GroupDocs");//If the document does not contain this text, nothing will be highlighted + searchTextFragment.setFontSize(10.); + searchTextFragment.setFontFamily("Calibri"); + searchTextFragment.setFontColor(65535); + searchTextFragment.setBackgroundColor(16761035); + annotator.add(searchTextFragment); + annotator.save("result_add_search_text.pdf"); + } + } +} diff --git a/Examples/src/main/java/com/groupdocs/annotation/examples/basic_usage/add_annotation_to_the_document/AddSquigglyAnnotation.java b/Examples/src/main/java/com/groupdocs/annotation/examples/basic_usage/add_annotation_to_the_document/AddSquigglyAnnotation.java new file mode 100644 index 0000000..30ed322 --- /dev/null +++ b/Examples/src/main/java/com/groupdocs/annotation/examples/basic_usage/add_annotation_to_the_document/AddSquigglyAnnotation.java @@ -0,0 +1,48 @@ +package com.groupdocs.annotation.examples.basic_usage.add_annotation_to_the_document; + +import com.groupdocs.annotation.Annotator; +import com.groupdocs.annotation.examples.Constants; +import com.groupdocs.annotation.models.Point; +import com.groupdocs.annotation.models.Reply; +import com.groupdocs.annotation.models.annotationmodels.SquigglyAnnotation; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class AddSquigglyAnnotation { + public static void run() { + try(final Annotator annotator = new Annotator(Constants.INPUT_PDF)){ + SquigglyAnnotation squigglyAnnotation = new SquigglyAnnotation(); + squigglyAnnotation.setCreatedOn(new Date()); + squigglyAnnotation.setFontColor(65535); + squigglyAnnotation.setBackgroundColor(16761035); + squigglyAnnotation.setMessage("This is squiggly annotation"); + squigglyAnnotation.setOpacity(0.7); + squigglyAnnotation.setPageNumber(0); + squigglyAnnotation.setSquigglyColor(1422623);//Supported only Word and PDF + List points = new ArrayList(); + points.add(new Point(80, 730)); + points.add(new Point(240, 730)); + points.add(new Point(80, 650)); + points.add(new Point(240, 650)); + + Reply reply1 = new Reply(); + reply1.setComment("First comment"); + reply1.setRepliedOn(new Date()); + + Reply reply2 = new Reply(); + reply2.setComment("Second comment"); + reply2.setRepliedOn(new Date()); + + List replies = new ArrayList<>(); + replies.add(reply1); + replies.add(reply2); + + squigglyAnnotation.setReplies(replies); + + annotator.add(squigglyAnnotation); + annotator.save("result_squiggly_annotation.pdf"); + } + } +}