public void DeleteAllRows(string sessionId, string docId, string fieldName)
        {
            var ds = new CaptureDocumentService();

            // Get row count
            var tableValues = ds.GetDocumentTableFieldValue(sessionId, null, docId, new TableFieldIdentity()
            {
                //Id = tableId
                Name = fieldName
            });
            var rowCount = tableValues.Tables[0].Rows.Count;

            // Populate a collection with all indexes
            var rowIndexes = new RowIndexCollection();

            for (int row = 0; row < rowCount; row++)
            {
                rowIndexes.Add(new RowIndex()
                {
                    Index = row
                });
            }

            ds.DeleteTableFieldRow(sessionId, null, docId, fieldName, rowIndexes);
        }
Beispiel #2
0
        public void ExportFolderImages(string sessionId, string folderId, string outputFolder, string extension)
        {
            var    cds          = new CaptureDocumentService();
            var    folder       = cds.GetFolder(sessionId, null, folderId);
            string targetFolder = Path.Combine(outputFolder, folderId);

            Directory.CreateDirectory(targetFolder);
            folder.Documents.ForEach(doc =>
            {
                ExportDocumentImages(sessionId, doc.Id, targetFolder, extension);
            });
        }
Beispiel #3
0
        public void ExportFolderJson(string sessionId, string folderId, string outputFolder)
        {
            var    serializer   = new DataContractJsonSerializer(typeof(ExportDocument));
            var    cds          = new CaptureDocumentService();
            var    exportDoc    = new ExportDocument();
            var    folder       = cds.GetFolder(sessionId, null, folderId);
            string targetFolder = Path.Combine(outputFolder, folderId);

            exportDoc.FolderFields = folder.Fields;
            Directory.CreateDirectory(targetFolder);
            folder.Documents.ForEach(doc =>
            {
                ExportDocumentJson(sessionId, doc.Id, targetFolder);
            });
        }
        /// <summary>
        /// Calls SaveSourceFile for each document in a folder and returns an array with the resulting
        /// file paths.  Use SaveSourceFilesOpmt for an OPMT system.
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="folderId"></param>
        /// <param name="folderPath"></param>
        /// <returns>array with the resulting file paths.  Suitable for mapping to a dynamic complex variable with one string column,
        /// and mapping to the attachment field of an email activity.</returns>
        public string[] SaveSourceFiles(string sessionId, string folderId, string folderPath)
        {
            var ds     = new CaptureDocumentService();
            var folder = ds.GetFolder(sessionId, null, folderId);
            var files  = new List <string>();

            if (folder.Documents != null)
            {
                foreach (var doc in folder.Documents)
                {
                    files.Add(SaveSourceFile(sessionId, doc.Id, folderPath));
                }
            }

            return(files.ToArray <string>());
        }
Beispiel #5
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 #6
0
        /// <summary>
        /// Returns collection of Word objects from given document and page index (0-based)
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="documentId"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public WordCollection DocPageWords(string sessionId, string documentId, int pageIndex)
        {
            var      ds = new CaptureDocumentService();
            Document d  = ds.GetDocument(sessionId, null, documentId);

            // If needed, it is nicer to return an empty collection instead of null
            WordCollection words = new WordCollection();

            // index is 0 based, Number is 1 based
            if (pageIndex >= d.NumberOfPages)
            {
                // Could throw exception here
                Debug.WriteLine("Page index {pageIndex} does not exist!");
                return(words);
            }

            Page p = d.Pages[pageIndex];

            // Build the request for specific properties from specific pages
            // 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"
                    }
                })
            };

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

            // Property object per page (although in this case, only requesting from a single page)
            foreach (PageProperties pageProps in pageProperties)
            {
                words = (WordCollection)pageProps.PropertyCollection.Where(x => x.SystemFieldIdentity.Name == "Words").FirstOrDefault()?.Value;
            }

            // In case of null, use empty collection
            words = words ?? new WordCollection();

            return(words);
        }
Beispiel #7
0
        public FuzzyRecordDisplay[] Search(string sessionId, string searchText, string dbName)
        {
            // ideally this should match the separation characters defined in the fuzzy database config
            var separatorChars = new char[] { ' ', ',', '-' };

            var dbId = new FuzzyDatabaseIdentity()
            {
                Name        = "ASD",
                DisplayName = "ASD"
            };

            //var filter= new FuzzySearchFilter()
            //{
            //    FieldName
            //}

            var filter = new FuzzySearchFilter()
            {
                FieldName  = "PRESIDENT",
                FilterText = "James Madisin"
            };

            var filters = new FuzzySearchFilterCollection();

            filters.Add(filter);

            var query = new SearchQuery()
            {
                SearchWords          = searchText.Split(separatorChars),
                NumberOfRowsToReturn = 10,
                FuzzySearchFilters   = filters
            };

            var dt = new DocumentTypeIdentity()
            {
                Id = "954E417148294312B4FE6452BE25FE48"
            };

            var ds = new CaptureDocumentService();

            var result = ds.SearchFuzzyDatabase(sessionId, dbId, query, dt);

            return(FuzzyRecordDisplay.FromSearchResult(result));
        }
        /// <summary>
        /// Return original filename.  In case of no original filename, "DocId-{DocIdGUID}".
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="documentId"></param>
        /// <returns></returns>
        public static string OriginalFilenameOrDocId(string sessionId, string documentId)
        {
            string OriginalFileName = string.Empty;
            var    ds = new CaptureDocumentService();

            try
            {
                OriginalFileName = ds.GetTextExtension(sessionId, null, documentId, "Kofax.CEBPM.FileName");
            }
            catch (Exception ex)
            {
                Debug.Print($"Error getting original name: {ex.Message}");
            }

            if (string.IsNullOrWhiteSpace(OriginalFileName))
            {
                OriginalFileName = "DocId-" + documentId;
            }

            return(OriginalFileName);
        }
Beispiel #9
0
        public string DocField(string sessionId, Document d, RuntimeFieldData f)
        {
            var s  = new StringBuilder($"Field: {f.Name}");
            var ds = new CaptureDocumentService();

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

            var fpic = new FieldPropertiesIdentityCollection()
            {
                new FieldPropertiesIdentity()
                {
                    Identity = new RuntimeFieldIdentity(f.Id),
                    FieldSystemProperties = new FieldSystemPropertyIdentityCollection()
                    {
                        new FieldSystemPropertyIdentity()
                        {
                            Name = "OriginalText",
                            Id   = "E52E91102A6B4052A4B35CD71E4B0016"
                        }
                    }
                }
            };

            var fpc = ds.GetDocumentFieldPropertyValues(sessionId, null, d.Id, fpic);

            // for each field returned (only one here)
            foreach (var fp in fpc)
            {
                // for each property
                foreach (var fsp in fp.PropertyCollection)
                {
                    s.AppendLine($"{fsp.SystemFieldIdentity.Name} = {fsp.Value}");
                }
            }

            return(s.ToString());
        }
        /// <summary>
        /// OPMT can only send email from the file system from the specific tenant's generated documents path.  The email activity will
        /// add that path when trying to get the file, so this function will save to that folder, then return only file names instead of
        /// full paths.  That way the return value can be used directly in the email activity's attachment field.
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="folderId"></param>
        /// <param name="tenantName"></param>
        /// <param name="live">True if live, false if dev</param>
        /// <returns>array with the resulting file names.  Suitable for mapping to a dynamic complex variable with one string column,
        /// and mapping to the attachment field of an email activity.</returns>
        public string[] SaveSourceFilesOpmt(string sessionId, string folderId, string tenantName, bool live)
        {
            var ds     = new CaptureDocumentService();
            var folder = ds.GetFolder(sessionId, null, folderId);
            var files  = new List <string>();

            string tenant     = tenantName + "_" + (live ? "live" : "dev");
            string folderPath = @"C:\ProgramData\Kofax\TotalAgility\Tenants\" + tenant + @"\Generated Documents\";

            if (folder.Documents != null)
            {
                foreach (var doc in folder.Documents)
                {
                    string filePath = SaveSourceFile(sessionId, doc.Id, folderPath);
                    var    file     = new FileInfo(filePath);
                    // just add the file name within the OPMT generated docs folder for the given tenant and "liveness"
                    files.Add(file.Name);
                }
            }

            return(files.ToArray <string>());
        }
Beispiel #11
0
    public static void GetAnnotationInfo(string sessionId, string docId)
    {
        var cds = new CaptureDocumentService();

        // get all annotations
        var annotations = cds.GetAnnotations(sessionId, docId);

        annotations.ForEach(x =>
        {
            Console.WriteLine($"{x.GetType()} @ {x.Location.ToString()}");
        });

        // get sticky notes
        var doc = cds.GetDocument(sessionId, null, docId);

        doc.Pages.ForEach(p =>
        {
            p.Annotations.ForEach(x =>
            {
                Console.WriteLine($"{x.Text} @ {x.Top}, {x.Left}");
            });
        });
    }
        /// <summary>
        /// Saves the document as a multipage tiff with original filename (doc GUID if no name)
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="documentId"></param>
        /// <param name="folderPath"></param>
        /// <param name="AppendToFilename"></param>
        /// <returns></returns>
        public string SaveTiff(string sessionId, string documentId, string folderPath, string AppendToFilename)
        {
            string FileName = OriginalFilenameOrDocId(sessionId, documentId);

            if (!String.IsNullOrWhiteSpace(AppendToFilename))
            {
                FileName = $"{Path.GetFileNameWithoutExtension(FileName)} - {AppendToFilename}";
            }
            var    ds = new CaptureDocumentService();
            string filePath;

            try
            {
                filePath = ds.GetDocumentAsFile(sessionId, documentId, folderPath, FileName);
            }
            catch (Exception ex)
            {
                filePath = Path.Combine(folderPath, $"{FileName}-error.txt");
                File.WriteAllText(filePath, ex.ToString());
            }

            return(filePath);
        }
        /// <summary>
        /// This tries to save the source file of a document to the given folder, using the original file name stored in
        /// the text extension named "Kofax.CEBPM.FileName" if it exists.  If the text extension does not exist, then the filename is
        /// "UnknownOriginalName-" + documentId (no file extension).
        /// If the input files for the document were tiffs, then no source file exists and a multi-page tiff is saved (".tiff").
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="documentId"></param>
        /// <param name="folderPath"></param>
        /// <returns></returns>
        public string SaveSourceFile(string sessionId, string documentId, string folderPath)
        {
            string OriginalFileName = OriginalFilenameOrDocId(sessionId, documentId);

            var filePath = Path.Combine(folderPath, OriginalFileName);

            Debug.Print($"Writing source file to path: {filePath}");

            DocumentSourceFile sourceFile = null;

            var ds = new CaptureDocumentService();

            try
            {
                // Get the source file which will not exist if the source was tif
                sourceFile = ds.GetSourceFile(sessionId, null, documentId);
            }
            catch (Exception ex)
            {
                Debug.Print($"Could not get source file: {ex.Message}");
            }

            if (sourceFile != null && sourceFile.SourceFile != null)
            {
                Debug.Print($"Source file mime type: {sourceFile.MimeType}");

                File.WriteAllBytes(filePath, sourceFile.SourceFile);
            }
            else
            {
                // If no source file, get doc file as multipage tif
                filePath = ds.GetDocumentAsFile(sessionId, documentId, folderPath, OriginalFileName);
            }

            return(filePath);
        }
Beispiel #14
0
        public string ExportDocumentJson(string sessionId, string documentId, string outputFolder)
        {
            var    serializer   = new DataContractJsonSerializer(typeof(ExportDocument));
            var    cds          = new CaptureDocumentService();
            var    exportDoc    = new ExportDocument();
            var    doc          = cds.GetDocument(sessionId, null, documentId);
            string folderId     = doc.ParentId;
            var    folder       = cds.GetFolder(sessionId, null, folderId);
            string targetFolder = outputFolder;

            exportDoc.FolderFields = folder.Fields;
            Directory.CreateDirectory(targetFolder);
            exportDoc.Fields = doc.Fields;
            var fileName = Path.Combine(
                targetFolder,
                doc.Id + ".json");

            using (var fs = File.Create(fileName))
            {
                serializer.WriteObject(fs, exportDoc);
            }

            return(fileName);
        }
Beispiel #15
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());
        }