GroupDocsGists
10/24/2017 - 1:18 PM

Examples-GroupDocs.Annotation.Examples.Java-src-main-java-GroupDocs-Annotation-Examples-Java-AnnotateDocuments-addUnderlineAnnotationInWords.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 underline annotations
	AnnotationInfo underlineAnnotation = new AnnotationInfo();
	underlineAnnotation.setPageNumber(2);
	underlineAnnotation.setSvgPath(
			"[{\"x\":415.17499,\"y\":628.874},{\"x\":511.85101,\"y\":628.874},{\"x\":415.17499,\"y\":619.874},{\"x\":511.85101,\"y\":619.874}]");
	underlineAnnotation.setType(AnnotationType.TextUnderline);
	annotations.add(underlineAnnotation);
	// 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();
}