/// <summary> /// Returns a list of annotations for a document /// </summary> /// <param name="connectionId">Socket connection identifier to validate user permissions for</param> /// <param name="fileId">The document path to get annotations for</param> /// <returns>An instance of an object containing information document annotations</returns> public ListAnnotationsResult ListAnnotations(string connectionId, string fileId) { var reviewer = _annotationBroadcaster.GetConnectionUser(connectionId); if (reviewer == null) { throw new AnnotatorException("There is no such reviewer."); } var user = _userSvc.GetUserByGuid(reviewer.Value.UserGuid); var document = GetDocument(fileId, user.Id); if (document == null) { _documentSvc.Add(new Document { OwnerId = user.Id, Name = fileId, CreatedOn = DateTime.Now, Guid = Guid.NewGuid().ToString() }); document = _documentSvc.GetDocument(fileId); } return(_mapper.Map <ListAnnotationsResult>(_annotator.GetAnnotations(document.Id, null, user.Id))); }
/// <summary> /// Gets annotations from the storage file /// </summary> /// <returns>Returns a list of annotations</returns> public static ListAnnotationsResult GetAllDocumentAnnotation() { try { //ExStart:GetAllAnnotation // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); IDocumentDataHandler documentRepository = annotator.GetDocumentDataHandler(); if (!Directory.Exists(cfg.StoragePath)) { Directory.CreateDirectory(cfg.StoragePath); } // Create document data object in storage. var document = documentRepository.GetDocument("Document.pdf"); long documentId = document != null ? document.Id : annotator.CreateDocument("Document.pdf"); // Get annotation from storage ListAnnotationsResult result = annotator.GetAnnotations(documentId); return(result); //ExEnd:GetAllAnnotation } catch (System.Exception exp) { Console.WriteLine(exp.Message); return(null); } }
/// <summary> /// Removes annotations /// </summary> public static void RemoveAnnotation() { try { //ExStart:RemoveAnnotation // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); IDocumentDataHandler documentRepository = annotator.GetDocumentDataHandler(); if (!Directory.Exists(cfg.StoragePath)) { Directory.CreateDirectory(cfg.StoragePath); } // Create document data object in storage. var document = documentRepository.GetDocument("Document.pdf"); long documentId = document != null ? document.Id : annotator.CreateDocument("Document.pdf"); // Create annotation object AnnotationInfo pointAnnotation = new AnnotationInfo { AnnotationPosition = new Point(852.0, 81.0), Box = new Rectangle(212f, 81f, 142f, 0.0f), Type = AnnotationType.Point, PageNumber = 0, CreatorName = "Anonym", DocumentGuid = documentId }; // Get all annotations from storage ListAnnotationsResult listAnnotationsResult = annotator.GetAnnotations(documentId); // Get annotation var annotation = annotator.GetAnnotation(listAnnotationsResult.Annotations[0].Guid); // Delete single annotation var deleteAnnotationResult = annotator.DeleteAnnotation(annotation.Id); //Delete all annotations annotator.DeleteAnnotations(documentId); //ExEnd:RemoveAnnotation } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
// GET: Annotation public ActionResult List(string file) { Response.AddHeader("Content-Type", "application/json"); AnnotationImageHandler handler = Utils.createAnnotationImageHandler(); String filename = file; Document doc = Utils.findDocumentByName(filename); ListAnnotationsResult listResult = handler.GetAnnotations(doc.Id); List <GetAnnotationResult> list = new List <GetAnnotationResult>(); foreach (AnnotationInfo inf in listResult.Annotations) { list.Add(handler.GetAnnotation(inf.Guid)); } return(Content(JsonConvert.SerializeObject( list, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() } ), "application/json")); //Response.Write(list); /* * * response.setHeader("Content-Type", "application/json"); * AnnotationImageHandler imageHandler = Utils.createAnnotationImageHandler(); * String filename = request.getParameter("file"); * * Document doc = Utils.findDocumentByName(filename); * ListAnnotationsResult listResult = imageHandler.getAnnotations(doc.getId()); * * ArrayList<GetAnnotationResult> list = new ArrayList<>(); * for (AnnotationInfo inf : listResult.getAnnotations()) { * list.add(imageHandler.getAnnotation(inf.getGuid())); * } * * new ObjectMapper().writeValue(response.getOutputStream(), list);*/ return(View()); }
public ActionResult Get(string file) { Response.AddHeader("Content-Type", "application/json"); AnnotationImageHandler imageHandler = Utils.createAnnotationImageHandler(); String filename = file; Document doc = Utils.findDocumentByName(filename); ListAnnotationsResult listResult = imageHandler.GetAnnotations(doc.Id); List <GetAnnotationResult> list = new List <GetAnnotationResult>(); foreach (AnnotationInfo inf in listResult.Annotations) { list.Add(imageHandler.GetAnnotation(inf.Guid)); } return(Content(JsonConvert.SerializeObject( list, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() } ), "application/json")); }
public ActionResult Get(string file) { AnnotationImageHandler imageHandler = Utils.createAnnotationImageHandler(); String filename = file; Document document = Utils.findDocumentByName(filename); List <AnnotationInfo> list = imageHandler.GetAnnotations(document.Id).Annotations.ToList <AnnotationInfo>(); Stream exported; using (FileStream original = new FileStream(Utils.getStoragePath() + "/" + filename, FileMode.Open)) { exported = imageHandler.ExportAnnotationsToDocument(original, list); } Response.AddHeader("Content-Type", "application/octet-stream"); //Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); using (var ms = new MemoryStream()) { exported.CopyTo(ms); return(File(ms.ToArray(), "application/octet-stream", file)); } }