GroupDocsGists
10/24/2017 - 1:19 PM

Examples-GroupDocs.Annotation.Examples.Java-src-main-java-GroupDocs-Annotation-Examples-Java-AnnotateDocuments-addPointAnnotationInPDF.java

// For complete examples and data files, please go to https://github.com/groupdocs-annotation/GroupDocs.Annotation-for-Java
try {
	AnnotationConfig cfg = Utilities.getConfiguration();
	AnnotationImageHandler annotator = new AnnotationImageHandler(cfg);
	annotator.getDocumentDataHandler();
	InputStream cleanPdf = new FileInputStream(Utilities.storagePath + File.separator + fileName);
	List<AnnotationInfo> annotations = new ArrayList<AnnotationInfo>();
	// Point annotation
	AnnotationInfo pointAnnotation = new AnnotationInfo();
	pointAnnotation.setAnnotationPosition(new Point(852.0, 81.0));
	pointAnnotation.setBox(new Rectangle(212f, 81f, 35f, 0.0f));
	pointAnnotation.setPageNumber(0);
	pointAnnotation.setType(AnnotationType.Point);
	pointAnnotation.setCreatorName("Anonym A.");
	annotations.add(pointAnnotation);
	// Add annotation to the document
	InputStream result = annotator.exportAnnotationsToDocument(cleanPdf, annotations, DocumentType.Pdf);
	// Save result stream to file.
	OutputStream fileStream = new FileOutputStream(
			Utilities.outputPath + File.separator + "annotated-point.pdf");
	IOUtils.copy(result, fileStream);
} catch (Exception e) {
	System.out.println("Exception:" + e.getMessage());
	e.printStackTrace();
}