GroupDocsGists
10/24/2017 - 1:20 PM

Examples-GroupDocs.Annotation.Examples.Java-src-main-java-GroupDocs-Annotation-Examples-Java-DataStorage-createAndGetAnnotations.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 annotation from storage
	GetAnnotationResult result = annotator.getAnnotation(createPointAnnotationResult.getGuid());
	return result;
} catch (Exception e) {
	System.out.println("Exception: " + e.getMessage());
	e.printStackTrace();
	return null;
}