GroupDocsGists
10/24/2017 - 1:20 PM

Examples-GroupDocs.Annotation.Examples.Java-src-main-java-GroupDocs-Annotation-Examples-Java-DataStorage-removeAnnotation.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);
	IDocumentDataHandler documentRepository = annotator.getDocumentDataHandler();
	// Create document data object in storage.
	Document document = documentRepository.getDocument(fileName);
	long documentId = document == null ? annotator.createDocument(fileName) : document.getId();
	// Create annotation object
	AnnotationInfo pointAnnotation = new AnnotationInfo();
	pointAnnotation.setAnnotationPosition(new Point(852.0, 81.0));
	pointAnnotation.setBox(new Rectangle(212f, 81f, 142f, 0.0f));
	pointAnnotation.setType(AnnotationType.Point);
	pointAnnotation.setPageNumber(0);
	pointAnnotation.setCreatorName("Anonym A.");
	pointAnnotation.setDocumentGuid(documentId);
	// Add annotation to storage
	CreateAnnotationResult createPointAnnotationResult = annotator.createAnnotation(pointAnnotation);
	// Get all annotations from storage
	ListAnnotationsResult listAnnotationsResult = annotator.getAnnotations(documentId);
	// Get annotation
	GetAnnotationResult annotation = annotator
			.getAnnotation(listAnnotationsResult.getAnnotations()[0].getGuid());
	// Delete annotation
	DeleteAnnotationResult deleteAnnotationResult = annotator.deleteAnnotation(annotation.getId());
	// Delete all annotations
	annotator.deleteAnnotations(documentId);
	System.out.println(deleteAnnotationResult);
} catch (Exception e) {
	System.out.println("Exception: " + e.getMessage());
	e.printStackTrace();
}