public string Export(long documentId, string fileId, long userId) { using (Stream inputDoc = _annotator.GetPdfFile(fileId).Stream) { var resultStream = _annotator.ExportAnnotationsToDocument(documentId, inputDoc, DocumentType.Pdf, userId); var fileName = string.Format("{0}_WithComments_{1}.{2}", Path.GetFileNameWithoutExtension(fileId), DateTime.UtcNow.ToString("yyyy-MM-dd HH-mm-ss"), "pdf"); string tempFilePath = Path.Combine(storagePath + "//Temp", fileName); try { using (var fs = new FileStream(tempFilePath, FileMode.Create)) { resultStream.Position = 0; resultStream.CopyTo(fs); } } catch (Exception e) { throw new AnnotatorException("Failed to save output file to the storage."); } return(Path.Combine("Temp", fileName)); } }
/// <summary> /// Picks the annotations from document.pdf and exports them to sample.pdf /// </summary> public static void ExportAnnotationInFile() { try { //ExStart:ExportAnnotationInFile // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); // Get file stream Stream manifestResourceStream = new FileStream(CommonUtilities.MapSourceFilePath(CommonUtilities.filePath), FileMode.Open, FileAccess.ReadWrite); List <AnnotationInfo> annotations = new List <AnnotationInfo>(); Stream stream = annotator.ExportAnnotationsToDocument(manifestResourceStream, annotations, DocumentType.Pdf); // Save result stream to file. using (FileStream fileStream = new FileStream(CommonUtilities.MapDestinationFilePath("Annotated.pdf"), FileMode.Create)) { byte[] buffer = new byte[stream.Length]; stream.Seek(0, SeekOrigin.Begin); stream.Read(buffer, 0, buffer.Length); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); } //ExEnd:ExportAnnotationInFile } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Adds Watermark annotation in Diagrams /// </summary> public static void AddWatermarkAnnotationInDiagrams() { try { //ExStart:AddWatermarkAnnotationInDiagrams // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); // Get input file stream Stream inputFile = new FileStream(CommonUtilities.MapSourceFilePath(CommonUtilities.filePath), FileMode.Open, FileAccess.ReadWrite); // Initialize list of AnnotationInfo List <AnnotationInfo> annotations = new List <AnnotationInfo>(); // Initialize watermark annotation AnnotationInfo watermarkAnnnotation = new AnnotationInfo() { Box = new Rectangle(165.41f, 192.24f, 177.8f, 38.29f), CreatedOn = DateTime.Now, FieldText = "Watermark text", FontColor = 16711680, FontFamily = "Microsoft Sans Serif", FontSize = 17, Opacity = 0.3, Type = AnnotationType.Watermark, }; // Add annotation to list annotations.Add(watermarkAnnnotation); // Get output file stream Stream result = annotator.ExportAnnotationsToDocument(inputFile, annotations); // Save result stream to file. using (FileStream fileStream = new FileStream(CommonUtilities.MapDestinationFilePath("Annotated.vsdx"), FileMode.Create)) { byte[] buffer = new byte[result.Length]; result.Seek(0, SeekOrigin.Begin); result.Read(buffer, 0, buffer.Length); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); } //ExEnd:AddWatermarkAnnotationInDiagrams } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
public string Export(long documentId, string fileId, long userId, string format) { var docType = DocumentType.Pdf; string extension = "pdf"; Stream inputDoc; switch (format) { case "words": docType = DocumentType.Words; extension = "docx"; inputDoc = _annotator.GetFile(fileId).Stream; break; case "slides": docType = DocumentType.Slides; extension = "pptx"; inputDoc = _annotator.GetFile(fileId).Stream; break; default: inputDoc = _annotator.GetPdfFile(fileId).Stream; break; } var resultStream = _annotator.ExportAnnotationsToDocument(documentId, inputDoc, docType, userId); inputDoc.Dispose(); string fileName = string.Format("{0}_WithComments_{1}.{2}", Path.GetFileNameWithoutExtension(fileId), DateTime.UtcNow.ToString("yyyy-MM-dd HH-mm-ss"), extension); string tempFilePath = Path.Combine(storagePath, fileName); try { using (var fs = new FileStream(tempFilePath, FileMode.Create)) { resultStream.Position = 0; resultStream.CopyTo(fs); } } catch (Exception e) { throw new AnnotatorException("Failed to save output file to the storage."); } return(fileName); }
/// <summary> /// Adds Distance annotation in Diagrams /// </summary> public static void AddDistanceAnnotationInDiagrams() { try { //ExStart:AddDistanceAnnotationInDiagrams // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); // Get input file stream Stream inputFile = new FileStream(CommonUtilities.MapSourceFilePath(CommonUtilities.filePath), FileMode.Open, FileAccess.ReadWrite); // Initialize list of AnnotationInfo List <AnnotationInfo> annotations = new List <AnnotationInfo>(); // Initialize distance annotation AnnotationInfo distanceAnnnotation = new AnnotationInfo { Box = new Rectangle((float)248.73202514648438, (float)287.85653686523438, (float)115.9178466796875, (float)25.143020629882812), CreatedOn = DateTime.Now, Opacity = 0.3, PageNumber = 0, SvgPath = "M248.73201877934272,295.5439436619718 l115.28309859154929,-4.192112676056338", Type = AnnotationType.Distance, }; // Add annotation to list annotations.Add(distanceAnnnotation); // Get output file stream Stream result = annotator.ExportAnnotationsToDocument(inputFile, annotations); // Save result stream to file. using (FileStream fileStream = new FileStream(CommonUtilities.MapDestinationFilePath("Annotated.vsdx"), FileMode.Create)) { byte[] buffer = new byte[result.Length]; result.Seek(0, SeekOrigin.Begin); result.Read(buffer, 0, buffer.Length); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); } //ExEnd:AddDistanceAnnotationInDiagrams } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Adds Point annotation in Diagrams /// </summary> public static void AddPointAnnotationInDiagrams() { try { //ExStart:AddPointAnnotationInDiagrams // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); // Get input file stream Stream inputFile = new FileStream(CommonUtilities.MapSourceFilePath(CommonUtilities.filePath), FileMode.Open, FileAccess.ReadWrite); // Initialize list of AnnotationInfo List <AnnotationInfo> annotations = new List <AnnotationInfo>(); // Initialize point annotation AnnotationInfo pointAnnnotation = new AnnotationInfo() { Box = new Rectangle(150.32f, 99.22f, 0, 0), CreatedOn = DateTime.Now, PageNumber = 0, Type = AnnotationType.Point, }; // Add annotation to list annotations.Add(pointAnnnotation); // Get output file stream Stream result = annotator.ExportAnnotationsToDocument(inputFile, annotations); // Save result stream to file. using (FileStream fileStream = new FileStream(CommonUtilities.MapDestinationFilePath("Annotated.vsdx"), FileMode.Create)) { byte[] buffer = new byte[result.Length]; result.Seek(0, SeekOrigin.Begin); result.Read(buffer, 0, buffer.Length); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); } //ExEnd:AddPointAnnotationInDiagrams } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Adds TextField annotation in Diagrams /// </summary> public static void AddTextFieldAnnotationInDiagrams() { try { //ExStart:AddTextFieldAnnotationInDiagrams // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); // Get input file stream Stream inputFile = new FileStream(CommonUtilities.MapSourceFilePath(CommonUtilities.filePath), FileMode.Open, FileAccess.ReadWrite); // Initialize list of AnnotationInfo List <AnnotationInfo> annotations = new List <AnnotationInfo>(); // Initialize textfield annotation AnnotationInfo textFieldAnnotation = new AnnotationInfo { CreatedOn = DateTime.Now, Type = AnnotationType.TextField, Box = new Rectangle(162.87f, 267.5f, 91.8f, 42.45f), BackgroundColor = -15988609, FieldText = "Annotation Text" }; // Add annotation to list annotations.Add(textFieldAnnotation); // Get output file stream Stream result = annotator.ExportAnnotationsToDocument(inputFile, annotations); // Save result stream to file. using (FileStream fileStream = new FileStream(CommonUtilities.MapDestinationFilePath("Annotated.vsdx"), FileMode.Create)) { byte[] buffer = new byte[result.Length]; result.Seek(0, SeekOrigin.Begin); result.Read(buffer, 0, buffer.Length); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); } //ExEnd:AddTextFieldAnnotationInDiagrams } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Adds Polyline annotation in Diagrams /// </summary> public static void AddPolylineAnnotationInDiagrams() { try { //ExStart:AddPolylineAnnotationInDiagrams // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); // Get input file stream Stream inputFile = new FileStream(CommonUtilities.MapSourceFilePath(CommonUtilities.filePath), FileMode.Open, FileAccess.ReadWrite); // Initialize list of AnnotationInfo List <AnnotationInfo> annotations = new List <AnnotationInfo>(); // Initialize polyline annotation AnnotationInfo polylineAnnotation = new AnnotationInfo { CreatedOn = DateTime.Now, Type = AnnotationType.Polyline, Box = new Rectangle(206.3f, 106.61f, 456.04f, 307.97f), SvgPath = "M436.293427230047,148.06338028169014l0,-0.9870892018779343l-0.9870892018779343,-0.9870892018779343l-1.9741784037558685,-0.9870892018779343l-0.9870892018779343,0l-0.9870892018779343,-0.9870892018779343l-1.9741784037558685,-0.9870892018779343l-0.9870892018779343,0l-1.9741784037558685,-0.9870892018779343l-1.9741784037558685,0l-4.935446009389671,-1.9741784037558685l-1.9741784037558685,0l-1.9741784037558685,-0.9870892018779343l-1.9741784037558685,0l-1.9741784037558685,-0.9870892018779343l-2.961267605633803,0l-2.961267605633803,0l-2.961267605633803,0l-2.961267605633803,0l-2.961267605633803,0l-2.961267605633803,0l-1.9741784037558685,0l-3.948356807511737,0l-2.961267605633803,0l-3.948356807511737,0l-4.935446009389671,0l-3.948356807511737,0.9870892018779343l-4.935446009389671,0.9870892018779343l-6.90962441314554,0l-3.948356807511737,0.9870892018779343l-3.948356807511737,0l-2.961267605633803,1.9741784037558685l-3.948356807511737,0.9870892018779343l-6.90962441314554,1.9741784037558685l-6.90962441314554,0.9870892018779343l-12.832159624413146,2.961267605633803l-6.90962441314554,1.9741784037558685l-5.922535211267606,0.9870892018779343l-5.922535211267606,1.9741784037558685l-5.922535211267606,1.9741784037558685l-5.922535211267606,0.9870892018779343l-4.935446009389671,1.9741784037558685l-5.922535211267606,1.9741784037558685l-5.922535211267606,1.9741784037558685l-4.935446009389671,1.9741784037558685l-5.922535211267606,2.961267605633803l-5.922535211267606,3.948356807511737l-5.922535211267606,3.948356807511737l-4.935446009389671,3.948356807511737l-5.922535211267606,3.948356807511737l-5.922535211267606,3.948356807511737l-3.948356807511737,5.922535211267606l- 3.948356807511737,4.935446009389671l-3.948356807511737,5.922535211267606l-3.948356807511737,6.90962441314554l-3.948356807511737,7.896713615023474l-0.9870892018779343,6.90962441314554l-1.9741784037558685,7.896713615023474l-1.9741784037558685,6.90962441314554l-0.9870892018779343,7.896713615023474l0,12.832159624413146l0,7.896713615023474l0,7.896713615023474l0.9870892018779343,7.896713615023474l1.9741784037558685,5.922535211267606l2.961267605633803,5.922535211267606l0.9870892018779343,5.922535211267606l2.961267605633803,6.90962441314554l3.948356807511737,5.922535211267606l4.935446009389671,4.935446009389671l3.948356807511737,5.922535211267606l3.948356807511737,5.922535211267606l3.948356807511737,5.922535211267606l5.922535211267606,5.922535211267606l5.922535211267606,5.922535211267606l5.922535211267606,5.922535211267606l6.90962441314554,5.922535211267606l7.896713615023474,5.922535211267606l7.896713615023474,5.922535211267606l17.767605633802816,8.883802816901408l11.845070422535212,3.948356807511737l11.845070422535212,4.935446009389671l23.690140845070424,8.883802816901408l41.45774647887324,6.90962441314554l31.586854460093896,3.948356807511737l16.780516431924884,0l16.780516431924884,1.9741784037558685l16.780516431924884,0l16.780516431924884,0l16.780516431924884,0l16.780516431924884,0l16.780516431924884,-1.9741784037558685l14.806338028169014,-1.9741784037558685l14.806338028169014,-1.9741784037558685l12.832159624413146,-1.9741784037558685l10.857981220657276,-2.961267605633803l10.857981220657276,-2.961267605633803l8.883802816901408,-4.935446009389671l8.883802816901408,-4.935446009389671l6.90962441314554,-6.90962441314554l6.90962441314554,-6.90962441314554l8.883802816901408,-16.780516431924884l4.935446009389671,-7.896713615023474l3.948356807511737,-8.883802816901408l4.935446009389671,-7.896713615023474l4.935446009389671,-7.896713615023474l3.948356807511737,-13.81924882629108l1.9741784037558685,-18.754694835680752l0,-7.896713615023474l0,-12.832159624413146l-1.9741784037558685,-15.793427230046948l-1.9741784037558685,-15.793427230046948l-4.935446009389671,-15.793427230046948l-8.883802816901408,-15.793427230046948l-12.832159624413146,-23.690140845070424l-10.857981220657276,-10.857981220657276l-5.922535211267606,-3.948356807511737l-12.832159624413146,-8.883802816901408l-9.870892018779342,-8.883802816901408l-5.922535211267606,-3.948356807511737l-12.832159624413146,-5.922535211267606l-15.793427230046948,-8.883802816901408l-13.81924882629108,-4.935446009389671l-11.845070422535212,-2.961267605633803l-11.845070422535212,-3.948356807511737l-11.845070422535212,-3.948356807511737l-5.922535211267606,-1.9741784037558685l-11.845070422535212,-2.961267605633803l-11.845070422535212,-1.9741784037558685l-5.922535211267606,-0.9870892018779343l-10.857981220657276,-1.9741784037558685l-10.857981220657276,-2.961267605633803l-9.870892018779342,0l-0.9870892018779343,0l-0.9870892018779343,0l-0.9870892018779343,0l-0.9870892018779343,0l0,-0.9870892018779343l1.9741784037558685,0", }; // Add annotation to list annotations.Add(polylineAnnotation); // Get output file stream Stream result = annotator.ExportAnnotationsToDocument(inputFile, annotations); // Save result stream to file. using (FileStream fileStream = new FileStream(CommonUtilities.MapDestinationFilePath("Annotated.vsdx"), FileMode.Create)) { byte[] buffer = new byte[result.Length]; result.Seek(0, SeekOrigin.Begin); result.Read(buffer, 0, buffer.Length); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); } //ExEnd:AddPolylineAnnotationInDiagrams } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Adds Resource Redaction annotation in Diagrams /// </summary> public static void AddResourceRedactionAnnotationInDiagrams() { try { //ExStart:AddResourceRedactionAnnotationInDiagrams // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); // Get input file stream Stream inputFile = new FileStream(CommonUtilities.MapSourceFilePath(CommonUtilities.filePath), FileMode.Open, FileAccess.ReadWrite); // Initialize list of AnnotationInfo List <AnnotationInfo> annotations = new List <AnnotationInfo>(); // Initialize resource reduction annotation AnnotationInfo resourceRedactionAnnotation = new AnnotationInfo { Type = AnnotationType.ResourcesRedaction, Box = new Rectangle(200, 114.5f, 282.3f, 103.7f), }; // Add annotation to list annotations.Add(resourceRedactionAnnotation); // Get output file stream Stream result = annotator.ExportAnnotationsToDocument(inputFile, annotations); // Save result stream to file. using (FileStream fileStream = new FileStream(CommonUtilities.MapDestinationFilePath("Annotated.vsdx"), FileMode.Create)) { byte[] buffer = new byte[result.Length]; result.Seek(0, SeekOrigin.Begin); result.Read(buffer, 0, buffer.Length); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); } //ExEnd:AddResourceRedactionAnnotationInDiagrams } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Adds Arrow annotation in Diagrams /// </summary> public static void AddArrowAnnotationInDiagrams() { try { //ExStart:AddArrowAnnotationInDiagrams // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); // Get input file stream Stream inputFile = new FileStream(CommonUtilities.MapSourceFilePath(CommonUtilities.filePath), FileMode.Open, FileAccess.ReadWrite); // Initialize list of AnnotationInfo List <AnnotationInfo> annotations = new List <AnnotationInfo>(); // Initialize arrow annotation AnnotationInfo arrowAnnotation = new AnnotationInfo { Type = AnnotationType.Arrow, Box = new Rectangle(435.77464788732397f, 148.05164319248826f, -66.34389671361504f, 53.07511737089203f) }; // Add annotation to list annotations.Add(arrowAnnotation); // Get output file stream Stream result = annotator.ExportAnnotationsToDocument(inputFile, annotations); // Save result stream to file. using (FileStream fileStream = new FileStream(CommonUtilities.MapDestinationFilePath("Annotated.vsdx"), FileMode.Create)) { byte[] buffer = new byte[result.Length]; result.Seek(0, SeekOrigin.Begin); result.Read(buffer, 0, buffer.Length); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); } //ExEnd:AddArrowAnnotationInDiagrams } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Import and Export Annotations from Words document. /// </summary> /// Update CommonUtilities.filePath with path to word document files before using this function public static void ImportAndExportAnnotationsFromWords() { try { //ExStart:ImportAndExportAnnotationsFromWords // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); // Get input file stream Stream inputFile = new FileStream(CommonUtilities.MapSourceFilePath(CommonUtilities.filePath), FileMode.Open, FileAccess.ReadWrite); //importing annotations from Words document AnnotationInfo[] annotations = annotator.ImportAnnotations(inputFile, DocumentType.Words); //export imported annotation to another document (just for check) Stream clearDocument = new FileStream(CommonUtilities.MapDestinationFilePath("Clear.docx"), FileMode.Open, FileAccess.ReadWrite); Stream output = annotator.ExportAnnotationsToDocument(clearDocument, annotations.ToList(), DocumentType.Words); // Export annotation and save output file //save results after export using (FileStream fileStream = new FileStream(CommonUtilities.MapDestinationFilePath("AnnotationImportAndExportAnnotated.docx"), FileMode.Create)) { byte[] buffer = new byte[output.Length]; output.Seek(0L, SeekOrigin.Begin); output.Read(buffer, 0, buffer.Length); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); } //ExEnd:ImportAndExportAnnotationsFromWords } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
//ExEnd:MapDestinationFilePath /// <summary> /// Saves output document /// </summary> public static void SaveOutputDocument(Stream inputFile, List <AnnotationInfo> annotations, DocumentType type) { try { //ExStart:SaveOutputDocument // 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); } Stream result = annotator.ExportAnnotationsToDocument(inputFile, annotations, type); FileStream getFileStream = inputFile as FileStream; string extensionWithDot = Path.GetExtension(getFileStream.Name); // Save result stream to file. using (FileStream fileStream = new FileStream(MapDestinationFilePath("Annotated" + extensionWithDot), FileMode.Create)) { byte[] buffer = new byte[result.Length]; result.Seek(0, SeekOrigin.Begin); result.Read(buffer, 0, buffer.Length); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); } //ExEnd:SaveOutputDocument } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
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)); } }
public HttpResponseMessage Annotate(AnnotationPostedDataEntity annotateDocumentRequest) { AnnotatedDocumentEntity annotatedDocument = new AnnotatedDocumentEntity(); try { // get/set parameters string documentGuid = annotateDocumentRequest.guid; string password = annotateDocumentRequest.password; string documentType = annotateDocumentRequest.documentType; AnnotationDataEntity[] annotationsData = annotateDocumentRequest.annotationsData; // initiate AnnotatedDocument object // initiate list of annotations to add List <AnnotationInfo> annotations = new List <AnnotationInfo>(); // get document info - required to get document page height and calculate annotation top position string fileName = System.IO.Path.GetFileName(documentGuid); FileInfo fi = new FileInfo(documentGuid); DirectoryInfo parentDir = fi.Directory; string documentPath = ""; string parentDirName = parentDir.Name; if (parentDir.FullName == GlobalConfiguration.Annotation.FilesDirectory.Replace("/", "\\")) { documentPath = fileName; } else { documentPath = Path.Combine(parentDirName, fileName); } DocumentInfoContainer documentInfo = AnnotationImageHandler.GetDocumentInfo(documentPath, password); // check if document type is image if (SupportedImageFormats.Contains(Path.GetExtension(documentGuid))) { documentType = "image"; } // initiate annotator object string notSupportedMessage = ""; for (int i = 0; i < annotationsData.Length; i++) { // create annotator AnnotationDataEntity annotationData = annotationsData[i]; PageData pageData = documentInfo.Pages[annotationData.pageNumber - 1]; // add annotation, if current annotation type isn't supported by the current document type it will be ignored try { BaseAnnotator annotator = AnnotatorFactory.createAnnotator(annotationData, pageData); if (annotator.IsSupported(documentType)) { annotations.Add(annotator.GetAnnotationInfo(documentType)); } else { notSupportedMessage = annotator.Message; } } catch (System.Exception ex) { throw new System.Exception(ex.Message, ex); } } // Add annotation to the document DocumentType type = DocumentTypesConverter.GetDocumentType(documentType); // Save result stream to file. string path = GlobalConfiguration.Annotation.OutputDirectory + Path.DirectorySeparatorChar + fileName; if (File.Exists(path)) { RemoveAnnotations(path); } // check if annotations array contains at least one annotation to add if (annotations.Count != 0) { Stream cleanDoc = new FileStream(documentGuid, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); Stream result = AnnotationImageHandler.ExportAnnotationsToDocument(cleanDoc, annotations, type); cleanDoc.Dispose(); cleanDoc.Close(); // Save result stream to file. using (FileStream fileStream = new FileStream(path, FileMode.Create)) { byte[] buffer = new byte[result.Length]; result.Seek(0, SeekOrigin.Begin); result.Read(buffer, 0, buffer.Length); fileStream.Write(buffer, 0, buffer.Length); fileStream.Close(); } } else { return(Request.CreateResponse(HttpStatusCode.OK, new Resources().GenerateException(new NotSupportedException(notSupportedMessage)))); } annotatedDocument = new AnnotatedDocumentEntity() { guid = path, }; } catch (System.Exception ex) { // set exception message return(Request.CreateResponse(HttpStatusCode.OK, new Resources().GenerateException(ex))); } return(Request.CreateResponse(HttpStatusCode.OK, annotatedDocument)); }