GroupDocsGists
10/24/2017 - 1:20 PM

Examples-GroupDocs.Annotation.Examples.Java-src-main-java-GroupDocs-Annotation-Examples-Java-DataStorage-editTextFieldAnnotations.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 textFieldAnnotation = new AnnotationInfo();
	textFieldAnnotation.setAnnotationPosition(new Point(852.0, 201.0));
	textFieldAnnotation.setFieldText("text in the box");
	textFieldAnnotation.setFontFamily("Arial");
	textFieldAnnotation.setFontSize(10);
	textFieldAnnotation.setBox(new Rectangle(66f, 201f, 64f, 37f));
	textFieldAnnotation.setPageNumber(0);
	textFieldAnnotation.setType(AnnotationType.TextField);
	textFieldAnnotation.setCreatorName("Anonym A.");
	textFieldAnnotation.setDocumentGuid(documentId);
	final CreateAnnotationResult createTextFieldAnnotationResult = annotator
			.createAnnotation(textFieldAnnotation);
	// Update text in the annotation
	final TextFieldInfo textFieldInfo = new TextFieldInfo();
	textFieldInfo.setFieldText("new text");
	textFieldInfo.setFontFamily("Colibri");
	textFieldInfo.setFontSize(12);
	SaveAnnotationTextResult saveTextFieldResult = annotator
			.saveTextField(createTextFieldAnnotationResult.getId(), textFieldInfo);
	System.out.println(saveTextFieldResult);
	// Set text field color
	SaveAnnotationTextResult saveTextFieldColorResult = annotator
			.setTextFieldColor(createTextFieldAnnotationResult.getId(), 16753920);
	System.out.println(saveTextFieldColorResult);
} catch (Exception e) {
	System.out.println("Exception: " + e.getMessage());
	e.printStackTrace();
}