GroupDocsGists
10/24/2017 - 1:19 PM

Examples-GroupDocs.Annotation.Examples.Java-src-main-java-GroupDocs-Annotation-Examples-Java-AnnotateDocuments-addTextAnnotationInWords.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);
	InputStream cleanDoc = new FileInputStream(Utilities.storagePath + File.separator + fileName);
	List<AnnotationInfo> annotations = new ArrayList<AnnotationInfo>();
	// init possible types of annotations
	AnnotationInfo textAnnotation = new AnnotationInfo();
	textAnnotation.setPageNumber(1);
	textAnnotation.setSvgPath(
			"[{\"x\":186.698,\"y\":706.196},{\"x\":318.41201,\"y\":706.196},{\"x\":186.698,\"y\":697.196},{\"x\":318.41201,\"y\":697.196}]");
	textAnnotation.setType(AnnotationType.Text);
	textAnnotation.setText("Comment");
	annotations.add(textAnnotation);
	// Add annotation to the document
	InputStream result = annotator.exportAnnotationsToDocument(cleanDoc, annotations, DocumentType.Words);
	// Save result stream to file.
	OutputStream fileStream = new FileOutputStream(
			Utilities.outputPath + File.separator + "words-annotated.docx");
	System.out.println(result.available());
	IOUtils.copy(result, fileStream);
} catch (Exception e) {
	System.out.println("Exception: " + e.getMessage());
	e.printStackTrace();
}