Beispiel #1
0
        public string ExportDocumentImages(string sessionId, string documentId, string outputFolder, string extension)
        {
            var cds = new CaptureDocumentService();
            var doc = cds.GetDocument(sessionId, null, documentId);

            Directory.CreateDirectory(outputFolder);
            var fileName = Path.Combine(
                outputFolder,
                doc.Id + extension);

            using (var fs = File.Create(fileName))
            {
                var s = cds.GetDocumentFile(sessionId, null, doc.Id, "");
                s.CopyTo(fs);
            }
            return(fileName);
        }
Beispiel #2
0
        public string Details(string sessionId, string documentId)
        {
            var s  = new StringBuilder($"Id: {documentId}");
            var ds = new CaptureDocumentService();
            var d  = ds.GetDocument(sessionId, null, documentId);

            s.AppendLine();
            s.AppendLine(ReflectionHelper.PropertyList(d));
            s.AppendLine();

            string compressionName = string.Empty;

            try
            {
                using (var tiffstream = ds.GetDocumentFile(sessionId, null, documentId, "tiff"))
                    using (Image img = Image.FromStream(tiffstream))
                    {
                        compressionName = ImageData.GetCompressionName(img);
                    }
            }
            catch (Exception ex)
            {
                compressionName = $"Error: {ex.Message}";
            }
            s.AppendLine("GetDocumentFile TIFF Compression: " + compressionName);

            try
            {
                string filename = ds.GetDocumentAsFile(sessionId, documentId, System.IO.Path.GetTempPath(), Guid.NewGuid().ToString() + ".tif");
                using (Image img = Image.FromFile(filename))
                {
                    compressionName = ImageData.GetCompressionName(img);
                }
                System.IO.File.Delete(filename);
            }
            catch (Exception ex)
            {
                compressionName = $"Error: {ex.Message}";
            }
            s.AppendLine("GetDocumentAsFile TIFF Compression: " + compressionName);

            s.AppendLine();

            if (d.Fields != null)
            {
                foreach (var f in d.Fields)
                {
                    s.AppendLine(DocField(sessionId, d, f));
                }
            }

            s.AppendLine();
            s.AppendLine($"Pages: {d.NumberOfPages}");
            s.AppendLine();
            int pageIndex = 0;

            foreach (var p in d.Pages)
            {
                s.AppendLine($"Page {pageIndex + 1} of {d.NumberOfPages}");
                s.AppendLine(ReflectionHelper.PropertyList(p));
                s.AppendLine();

                if (p.Annotations != null)
                {
                    foreach (var a in p.Annotations)
                    {
                        s.AppendLine($"Page {a.PageIndex}: {a.Text} ({a.Author}, {a.Timestamp?.ToString() ?? "Unknown Time"}");
                    }
                }

                if (p.Barcodes != null)
                {
                    foreach (var b in p.Barcodes)
                    {
                        s.AppendLine(ReflectionHelper.PropertyList(b));
                    }
                }

                if (p.Words != null)
                {
                    s.AppendLine("Words property");
                    foreach (var w in p.Words)
                    {
                        s.AppendLine(ReflectionHelper.PropertyList(w));
                    }
                }

                //// See available properties: https://docshield.kofax.com/KTA/en_US/750-4kcae04o43/help/API/latest/class_agility_1_1_sdk_1_1_services_1_1_capture_document_service.html#a371ac5b01657cab2d46623c7f43f84b4
                //var ppic = new PagePropertiesIdentityCollection(){
                //    // Could request properties from more than one page here if needed
                //    new PagePropertiesIdentity(p.Id,  new FieldSystemPropertyIdentityCollection() {
                //        new FieldSystemPropertyIdentity() { Name = "Words" }
                //    })
                //};

                //var pageProperties = ds.GetPagePropertyValues(sessionId, documentId, ppic);

                WordCollection words = DocPageWords(sessionId, documentId, pageIndex);

                //foreach(var pageProps in pageProperties)
                //{
                //    words=(WordCollection)pageProps.PropertyCollection.Where(x => x.SystemFieldIdentity.Name == "Words").FirstOrDefault()?.Value;
                if (words != null)
                {
                    s.AppendLine("GetPagePropertyValues-Words property");
                    foreach (var w in words)
                    {
                        s.AppendLine($"{w.Text}");
                    }
                }

                //}

                pageIndex++;
            }

            return(s.ToString());
        }