Skip to content

Commit 6869a16

Browse files
Merge pull request #9 from atirtahirgroupdocs/master
Examples updated v17.1.0
2 parents ab74733 + 93bbb83 commit 6869a16

File tree

7 files changed

+442
-2
lines changed

7 files changed

+442
-2
lines changed
3.38 MB
Loading
140 KB
Loading
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package GroupDocs.Annotation.Examples.Java;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileNotFoundException;
6+
import java.io.FileOutputStream;
7+
import java.io.InputStream;
8+
import java.io.OutputStream;
9+
import java.util.ArrayList;
10+
import java.util.Date;
11+
12+
import org.apache.commons.io.IOUtils;
13+
14+
import com.groupdocs.annotation.domain.AnnotationInfo;
15+
import com.groupdocs.annotation.domain.AnnotationType;
16+
import com.groupdocs.annotation.domain.DocumentType;
17+
import com.groupdocs.annotation.domain.Rectangle;
18+
import com.groupdocs.annotation.domain.config.AnnotationConfig;
19+
import com.groupdocs.annotation.handler.AnnotationImageHandler;
20+
21+
public class ImagesAnnotation {
22+
//ExStart:ImagesAnnotation
23+
/*
24+
* document name
25+
*/
26+
public static String fileName = "image.png";
27+
public static void differentAnnotationsForImages() throws Throwable{
28+
AnnotationConfig cfg = Utilities.getConfiguration();
29+
AnnotationImageHandler annotator = new AnnotationImageHandler(cfg);
30+
//From version 17.1.0 you can work with images of JPG, TIFF, BMP and GIF(static without animation) format images
31+
FileInputStream cleanPresentation = new FileInputStream(Utilities.storagePath + File.separator + fileName);
32+
ArrayList<AnnotationInfo> annotations;
33+
annotations = new ArrayList<AnnotationInfo>();
34+
35+
AnnotationInfo textAnnotation = new AnnotationInfo();
36+
textAnnotation.setBox(new Rectangle(50, 510.9f, 454.73f, 29.08f));
37+
textAnnotation.setPageNumber(0);
38+
textAnnotation.setSvgPath("[{\"x\":200,\"y\":520.92},{\"x\":454.73,\"y\":520.92},{\"x\":200,\"y\":539.98},{\"x\":454.73,\"y\":539.98}]");
39+
textAnnotation.setType(AnnotationType.Text);
40+
textAnnotation.setCreatorName("Anonym A.");
41+
42+
AnnotationInfo textRedactionAnnotation = new AnnotationInfo();
43+
textRedactionAnnotation.setBox(new Rectangle(50, 510.9f, 454.73f, 29.08f));
44+
textRedactionAnnotation.setPageNumber(0);
45+
textRedactionAnnotation.setSvgPath("[{\"x\":200,\"y\":545.92},{\"x\":454.73,\"y\":545.92},{\"x\":200,\"y\":564.98},{\"x\":454.73,\"y\":564.98}]");
46+
textRedactionAnnotation.setType(AnnotationType.TextRedaction);
47+
textRedactionAnnotation.setCreatorName("Anonym A.");
48+
49+
AnnotationInfo strikeoutAnnotation = new AnnotationInfo();
50+
strikeoutAnnotation.setBox(new Rectangle(0, 510.92f, 454.73f, 29.08f));
51+
strikeoutAnnotation.setPageNumber(0);
52+
strikeoutAnnotation.setSvgPath("[{\"x\":120,\"y\":520.92},{\"x\":454.73,\"y\":520.92},{\"x\":120,\"y\":539.98},{\"x\":454.73,\"y\":539.98}]");
53+
strikeoutAnnotation.setType(AnnotationType.TextStrikeout);
54+
strikeoutAnnotation.setCreatorName("Anonym A.");
55+
56+
AnnotationInfo underlineAnnotation = new AnnotationInfo();
57+
underlineAnnotation.setBox(new Rectangle(0, 510.92f, 454.73f, 29.08f));
58+
underlineAnnotation.setPageNumber(0);
59+
underlineAnnotation.setSvgPath("[{\"x\":120,\"y\":520.92},{\"x\":454.73,\"y\":520.92},{\"x\":120,\"y\":539.98},{\"x\":454.73,\"y\":539.98}]");
60+
underlineAnnotation.setType(AnnotationType.TextUnderline);
61+
underlineAnnotation.setCreatorName("Anonym A.");
62+
63+
AnnotationInfo pointAnnotation = new AnnotationInfo();
64+
pointAnnotation.setPageNumber(0);
65+
pointAnnotation.setType(AnnotationType.Point);
66+
pointAnnotation.setBox(new Rectangle(100, 100, 0, 0));
67+
pointAnnotation.setFieldText("Hello!");
68+
pointAnnotation.setCreatorName("John");
69+
70+
AnnotationInfo areaAnnotation = new AnnotationInfo();
71+
areaAnnotation.setCreatedOn(new Date());
72+
areaAnnotation.setType(AnnotationType.Area);
73+
areaAnnotation.setPageNumber(0);
74+
areaAnnotation.setBox(new Rectangle(200, 72.7f, 50, 50));
75+
areaAnnotation.setBackgroundColor(-15988609);
76+
77+
AnnotationInfo polylineAnnotation = new AnnotationInfo();
78+
polylineAnnotation.setType(AnnotationType.Polyline);
79+
polylineAnnotation.setCreatedOn(new Date());
80+
polylineAnnotation.setBox(new Rectangle((float)250.82807922363281, (float)35.632957458496094, (float)102.70676422119141, (float)12.576337814331055));
81+
polylineAnnotation.setPageNumber(0);
82+
polylineAnnotation.setPenColor(65015);
83+
polylineAnnotation.setSvgPath(
84+
"M250.8280751173709,48.209295774647885l0.6986854460093896,0l0.6986854460093896, -1.3973708920187793l0.6986854460093896,"
85+
+ "0l0.6986854460093896,-1.3973708920187793l1.3973708920187793, -0.6986854460093896l0.6986854460093896,-0.6986854460093896l0.6986854460093896,0l2.096056338028169,"
86+
+ "-1.3973708920187793l3.493427230046948,-1.3973708920187793l0.6986854460093896,-0.6986854460093896l1.3973708920187793,"
87+
+ "-1.3973708920187793l0.6986854460093896,0l1.3973708920187793,-0.6986854460093896l0.6986854460093896,0l0.6986854460093896,"
88+
+ "-0.6986854460093896l0.6986854460093896,0l0.6986854460093896,0l0,-0.6986854460093896l0.6986854460093896,0l0.6986854460093896,"
89+
+ "0l1.3973708920187793,0l0,-0.6986854460093896l0.6986854460093896,0l1.3973708920187793,0l0.6986854460093896,0l1.3973708920187793,"
90+
+ "0l0.6986854460093896,0l2.096056338028169,-0.6986854460093896l1.3973708920187793,0l0.6986854460093896,0l0.6986854460093896,"
91+
+ "0l1.3973708920187793,0l1.3973708920187793,0l1.3973708920187793,0l2.096056338028169,0l5.589483568075117,0l1.3973708920187793,"
92+
+ "0l2.096056338028169,0l0.6986854460093896,0l1.3973708920187793,0l0.6986854460093896,0l1.3973708920187793,0l1.3973708920187793,"
93+
+ "0l0.6986854460093896,0.6986854460093896l1.3973708920187793,0l2.096056338028169,1.3973708920187793l0.6986854460093896,0l0.6986854460093896,"
94+
+ "0l0,0.6986854460093896l1.3973708920187793,0l0.6986854460093896,0.6986854460093896l1.3973708920187793,0.6986854460093896l0,"
95+
+ "0.6986854460093896l0.6986854460093896,0l1.3973708920187793,0.6986854460093896l1.3973708920187793,0.6986854460093896l3.493427230046948,"
96+
+ "0.6986854460093896l1.3973708920187793,0.6986854460093896l2.096056338028169,0.6986854460093896l1.3973708920187793,"
97+
+ "0.6986854460093896l1.3973708920187793,0l1.3973708920187793,0.6986854460093896l0.6986854460093896,0l0.6986854460093896,"
98+
+ "0.6986854460093896l1.3973708920187793,0l0.6986854460093896,0l0.6986854460093896,0l2.7947417840375586,0l1.3973708920187793,"
99+
+ "0l0.6986854460093896,0l1.3973708920187793,0l0.6986854460093896,0l0.6986854460093896,0l1.3973708920187793,"
100+
+ "0l0.6986854460093896,0l2.7947417840375586,0l0.6986854460093896,0l2.7947417840375586,0l1.3973708920187793,"
101+
+ "0l0.6986854460093896,0l0.6986854460093896,0l0.6986854460093896,0l0.6986854460093896,0l0.6986854460093896,"
102+
+ "0l0.6986854460093896,0l0.6986854460093896,-0.6986854460093896l0.6986854460093896,0"
103+
);
104+
105+
AnnotationInfo resourceRedactionAnnotation = new AnnotationInfo();
106+
resourceRedactionAnnotation.setCreatedOn(new Date());
107+
resourceRedactionAnnotation.setType(AnnotationType.ResourcesRedaction);
108+
resourceRedactionAnnotation.setPageNumber(0);
109+
resourceRedactionAnnotation.setBox(new Rectangle(100, 72.7f, 50, 50));
110+
111+
AnnotationInfo textFieldAnnotation = new AnnotationInfo();
112+
textFieldAnnotation.setCreatedOn(new Date());
113+
textFieldAnnotation.setType(AnnotationType.TextField);
114+
textFieldAnnotation.setPageNumber(0);
115+
textFieldAnnotation.setBox(new Rectangle(100, 72.7f, 50, 50));
116+
textFieldAnnotation.setFontColor(-15988609);
117+
textFieldAnnotation.setFieldText("some text");
118+
textFieldAnnotation.setFontFamily("times new roman");
119+
120+
AnnotationInfo watermarkAnnotation = new AnnotationInfo();
121+
watermarkAnnotation.setCreatedOn(new Date());
122+
watermarkAnnotation.setType(AnnotationType.Watermark);
123+
watermarkAnnotation.setFieldText("This is watermark");
124+
watermarkAnnotation.setFontFamily("arial");
125+
watermarkAnnotation.setBox(new Rectangle(200, 250, 50, 0));
126+
watermarkAnnotation.setFontSize(25);
127+
watermarkAnnotation.setFontColor(15988609);
128+
129+
AnnotationInfo distanceAnnotation = new AnnotationInfo();
130+
distanceAnnotation.setCreatedOn(new Date());
131+
distanceAnnotation.setType(AnnotationType.Distance);
132+
distanceAnnotation.setBox(new Rectangle(20, 20, 250, 250));
133+
distanceAnnotation.setBackgroundColor(-15988609);
134+
distanceAnnotation.setText("500px");
135+
distanceAnnotation.setFontFamily("Arial");
136+
137+
AnnotationInfo arrowAnnotation = new AnnotationInfo();
138+
arrowAnnotation.setCreatedOn(new Date());
139+
arrowAnnotation.setType(AnnotationType.Arrow);
140+
arrowAnnotation.setBox(new Rectangle(250, 72.7f, 0, 20));
141+
arrowAnnotation.setBackgroundColor(-15988609);
142+
143+
annotations.add(textAnnotation);
144+
annotations.add(pointAnnotation);
145+
annotations.add(areaAnnotation);
146+
annotations.add(textRedactionAnnotation);
147+
annotations.add(resourceRedactionAnnotation);
148+
annotations.add(polylineAnnotation);
149+
annotations.add(watermarkAnnotation);
150+
annotations.add(textFieldAnnotation);
151+
annotations.add(strikeoutAnnotation);
152+
annotations.add(underlineAnnotation);
153+
annotations.add(distanceAnnotation);
154+
annotations.add(arrowAnnotation);
155+
156+
InputStream result = annotator.exportAnnotationsToDocument(cleanPresentation, annotations, DocumentType.Images);
157+
158+
try (OutputStream fileStream = new FileOutputStream(Utilities.outputPath + File.separator + "Image-annotated.png")){
159+
System.out.println(result.available());
160+
IOUtils.copy(result, fileStream);
161+
}
162+
//ExEnd:ImagesAnnotation
163+
}
164+
}

Examples/GroupDocs.Annotation.Examples.Java/src/main/java/GroupDocs/Annotation/Examples/Java/MainClass.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class MainClass {
55
public static void main(String[] args) throws Throwable {
66

77
// apply license
8-
// Utilities.applyLicenseFromFile();
8+
Utilities.applyLicenseFromFile();
99

1010
// region Annotations for PDF
1111

@@ -147,6 +147,21 @@ public static void main(String[] args) throws Throwable {
147147

148148
// Get text coordinates in image representation of the document
149149
// Utilities.getTextCoordinates("sample.pdf");
150+
151+
// Importing annotations from word docs
152+
//WordsAnnotation.importingAnnotationsFromWordDoc();
153+
154+
// Creating different annotations for slides
155+
//SlidesAnnotation.differentAnnotationsForSlides();
156+
157+
// Importing annotations from slides
158+
//SlidesAnnotation.importingAnnotationsToSlide();
159+
160+
// Creating different annotations for image
161+
//ImagesAnnotation.differentAnnotationsForImages();
162+
163+
//Users With Different Rights
164+
//PDFAnnotation.usersWithDifferentRights();
150165

151166
}
152167

Examples/GroupDocs.Annotation.Examples.Java/src/main/java/GroupDocs/Annotation/Examples/Java/PDFAnnotation.java

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,24 @@
1111

1212
import org.apache.commons.io.IOUtils;
1313

14+
import com.groupdocs.annotation.common.exception.AnnotatorException;
1415
import com.groupdocs.annotation.domain.AnnotationInfo;
1516
import com.groupdocs.annotation.domain.AnnotationReplyInfo;
17+
import com.groupdocs.annotation.domain.AnnotationReviewerRights;
1618
import com.groupdocs.annotation.domain.AnnotationType;
1719
import com.groupdocs.annotation.domain.DocumentType;
1820
import com.groupdocs.annotation.domain.Point;
1921
import com.groupdocs.annotation.domain.Rectangle;
22+
import com.groupdocs.annotation.domain.ReviewerInfo;
2023
import com.groupdocs.annotation.domain.config.AnnotationConfig;
24+
import com.groupdocs.annotation.domain.results.CreateAnnotationResult;
25+
import com.groupdocs.annotation.domain.results.GetCollaboratorsResult;
26+
import com.groupdocs.annotation.domain.results.SetCollaboratorsResult;
2127
import com.groupdocs.annotation.handler.AnnotationImageHandler;
28+
import com.groupdocs.annotation.handler.input.IDocumentDataHandler;
29+
import com.groupdocs.annotation.handler.input.IUserDataHandler;
30+
import com.groupdocs.annotation.handler.input.dataobjects.Document;
31+
import com.groupdocs.annotation.handler.input.dataobjects.User;
2232

2333
public class PDFAnnotation {
2434

@@ -492,4 +502,81 @@ public static void addDistanceAnnotationInPDF() {
492502
//ExEnd:addDistanceAnnotationInPDF
493503
}
494504

505+
public static void usersWithDifferentRights(){
506+
//ExStart:usersWithDifferentRights
507+
AnnotationConfig cfg = Utilities.getConfiguration();
508+
AnnotationImageHandler annotator = new AnnotationImageHandler(cfg);
509+
IUserDataHandler userRepository = annotator.getUserDataHandler();
510+
IDocumentDataHandler documentRepository = annotator.getDocumentDataHandler();
511+
512+
// Create storage folder
513+
if(!new File(cfg.getStoragePath()).exists() && !new File(cfg.getStoragePath()).mkdirs())
514+
{
515+
System.out.println("Can't create directory!");
516+
}
517+
518+
// Create owner.
519+
User johnOwner = userRepository.getUserByEmail("john@doe.com");
520+
521+
if(johnOwner == null)
522+
{
523+
final User user = new User();
524+
user.setFirstName("John");
525+
user.setLastName("Doe");
526+
user.setEmail("john@doe.com");
527+
userRepository.add(user);
528+
johnOwner = userRepository.getUserByEmail("john@doe.com");
529+
}
530+
531+
// Create document data object in storage
532+
Document document = documentRepository.getDocument(fileName);
533+
long documentId = document == null ? annotator.createDocument(fileName, DocumentType.Pdf, johnOwner.getId()) : document.getId();
534+
535+
// Create reviewer.
536+
ReviewerInfo reviewerInfo = new ReviewerInfo();
537+
reviewerInfo.setPrimaryEmail("judy@doe.com");
538+
reviewerInfo.setFirstName("Judy");
539+
reviewerInfo.setLastName("Doe");
540+
reviewerInfo.setAccessRights(AnnotationReviewerRights.CanView);
541+
542+
// Add collaboorator to the document. If user with UserName equals to reviewers PrimaryEmail is absent it will be created.
543+
SetCollaboratorsResult addCollaboratorResult = annotator.addCollaborator(documentId, reviewerInfo);
544+
System.out.println(addCollaboratorResult);
545+
546+
// Get document collaborators
547+
GetCollaboratorsResult getCollaboratorsResult = annotator.getCollaborators(documentId);
548+
System.out.println(getCollaboratorsResult);
549+
User judy = userRepository.getUserByEmail("judy@doe.com");
550+
551+
// Create annotation object
552+
AnnotationInfo pointAnnotation = new AnnotationInfo();
553+
pointAnnotation.setAnnotationPosition(new Point(852.0, 81.0));
554+
pointAnnotation.setBox(new Rectangle(212f, 81f, 142f, 0.0f));
555+
pointAnnotation.setType(AnnotationType.Point);
556+
pointAnnotation.setPageNumber(0);
557+
pointAnnotation.setCreatorName("Anonym A.");
558+
559+
// John try to add annotations
560+
CreateAnnotationResult johnResult = annotator.createAnnotation(pointAnnotation, documentId, johnOwner.getId());
561+
System.out.println(johnResult);
562+
563+
// Judy try to add annotations
564+
try {
565+
CreateAnnotationResult judyResult = annotator.createAnnotation(pointAnnotation, documentId, judy.getId());
566+
System.out.println(judyResult);
567+
} catch (AnnotatorException e) {
568+
System.out.println(e.getMessage());
569+
}
570+
571+
// Allow Judy create annotations.
572+
reviewerInfo.setAccessRights(AnnotationReviewerRights.CanAnnotate);
573+
SetCollaboratorsResult updateCollaboratorResult = annotator.updateCollaborator(documentId, reviewerInfo);
574+
System.out.println(updateCollaboratorResult);
575+
576+
// Judy try to add annotations
577+
CreateAnnotationResult judyResultCanAnnotate = annotator.createAnnotation(pointAnnotation, documentId, judy.getId());
578+
System.out.println(judyResultCanAnnotate);
579+
//ExEnd:usersWithDifferentRights
580+
}
581+
495582
}

0 commit comments

Comments
 (0)