Example #1
0
        /// <summary>
        /// Removes all annotations in Images document
        /// </summary>
        public static void RemoveAllAnnotationsFromDocument()
        {
            try
            {
                //ExStart:RemoveAllAnnotationsFromDocument
                // 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);

                // Get output file stream
                Stream result = annotator.RemoveAnnotationStream(inputFile, DocumentType.Images);

                // Save result stream to file.
                using (FileStream fileStream = new FileStream(CommonUtilities.MapDestinationFilePath("Annotated.png"), 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:RemoveAllAnnotationsFromDocument
            }
            catch (System.Exception exp)
            {
                Console.WriteLine(exp.Message);
            }
        }
 public void RemoveAnnotations(string path)
 {
     try
     {
         Stream resultStream = null;
         string tempFilePath = "";
         using (Stream inputStream = File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
         {
             resultStream          = AnnotationImageHandler.RemoveAnnotationStream(inputStream);
             resultStream.Position = 0;
             tempFilePath          = new Resources().GetFreeFileName(GlobalConfiguration.Annotation.OutputDirectory, Path.GetFileName(path));
             using (Stream tempFile = File.Create(tempFilePath))
             {
                 resultStream.Seek(0, SeekOrigin.Begin);
                 resultStream.CopyTo(tempFile);
             }
             resultStream.Dispose();
             resultStream.Close();
         }
         File.Delete(path);
         File.Move(tempFilePath, path);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
Example #3
0
        private void SaveCleanDocument(Stream inputDoc, string fileId, DocumentType docType)
        {
            Stream resultClean = _annotator.RemoveAnnotationStream(inputDoc, docType);

            resultClean.Seek(0, SeekOrigin.Begin);
            var uploadDir = HttpContext.Current.Server.MapPath("~/App_Data");

            var filePath = Path.Combine(uploadDir, fileId);

            if (!Directory.Exists(uploadDir))
            {
                Directory.CreateDirectory(uploadDir);
            }
            using (var stream = File.Create(filePath))
            {
                resultClean.Seek(0, SeekOrigin.Begin);
                resultClean.CopyTo(stream);
            }
            inputDoc.Dispose();
            resultClean.Dispose();
        }
Example #4
0
        private void SaveCleanDocument(Stream inputDoc, string fileId)
        {
            Stream resultClean = _annotator.RemoveAnnotationStream(inputDoc, DocumentType.Pdf);
            string path        = Path.GetDirectoryName(fileId);
            var    uploadDir   = path != ""
                ? Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), path)
                : HttpContext.Current.Server.MapPath("~/App_Data");
            var fileName = string.Format("{0}.{1}",
                                         Path.GetFileNameWithoutExtension(fileId),
                                         "pdf");
            var filePath = Path.Combine(uploadDir, fileName);

            inputDoc.Dispose();
            if (!Directory.Exists(uploadDir))
            {
                Directory.CreateDirectory(uploadDir);
            }
            using (var stream = File.Create(filePath))
            {
                resultClean.CopyTo(stream);
            }
            resultClean.Dispose();
        }
        private void SaveCleanDocument(Stream inputDoc, string fileId)
        {
            Stream resultClean = _annotator.RemoveAnnotationStream(inputDoc, DocumentType.Pdf);
            string path        = Path.GetDirectoryName(fileId);
            var    uploadDir   = path != ""
                ? Path.Combine(pathFinder.GetApplicationPath() + "_layouts/15/GroupDocs_Annotation_SharePoint_WebPart/App_Data", path)
                : pathFinder.GetApplicationPath() + "_layouts/15/GroupDocs_Annotation_SharePoint_WebPart/App_Data";
            var fileName = string.Format("{0}.{1}",
                                         Path.GetFileNameWithoutExtension(fileId),
                                         "pdf");
            var filePath = Path.Combine(uploadDir, fileName);

            inputDoc.Dispose();
            if (!Directory.Exists(uploadDir))
            {
                Directory.CreateDirectory(uploadDir);
            }
            using (var stream = File.Create(filePath))
            {
                resultClean.CopyTo(stream);
            }
            resultClean.Dispose();
        }