将 Kofax Release 文档转换为二进制文件

convert Kofax Release document to binary

关于 Kofax Release,我想将每个扫描文档转换为字节数组。在我的 ReleaseDoc 方法中,我首先要检查文件是 PDF 文件还是 TIFF 文件。

用户可以在 ReleaseSetup 中设置一个布尔值,从而导致 'use PDF file if you have to decide between multiple file types'。

我刚刚创建了一个试图将文件转换为字节数组的片段。

如何检查我是否必须在 ReleaseDoc 方法中使用 PDF 或图像文件?

PDF文件是否有三页并不重要,因为它是一个文件。但是,如果有三个 TIFF 文件需要转换为一个字节数组,这很重要。我怎样才能做到这一点?

总而言之,在我的方法中我只需要一种从文档中提取名称和字节数组的方法。

    public KfxReturnValue ReleaseDoc()
    {
        try
        {
            string fileName = string.Empty;
            string filePath = string.Empty;

            bool isPDFFile = false; // how to check it?

            if (isPDFFile)
            {
                filePath = documentData.KofaxPDFPath;
                fileName = documentData.KofaxPDFFileName;
            }
            else
            {
                ImageFiles files = documentData.ImageFiles;

                if (files.Count == 1)
                {
                    fileName = files[0].FileName;
                    filePath = documentData.ImageFilePath;
                }
                else
                {
                    // Create one document out of multiple TIFF files?
                    // fileName = ...
                    // filePath = ...
                }
            }

            byte[] binaryFile = File.ReadAllBytes(filePath);

            // use fileName and binaryFile

            return KfxReturnValue.KFX_REL_SUCCESS;
        }
        catch (Exception e)
        {
            // Handle exception
            return KfxReturnValue.KFX_REL_ERROR;
        }
    }

不要手动合并 TIFF。这就是 ImageFiles 集合上的 Copy 方法的用途。这是一个简短的示例 - 您将得到两个字节数组,BinaryImage[]PdfImage[]。在发布期间,只需在尝试编写 PDF 之前检查是否为 null(如果 PDF 生成器未添加到队列中,您将不会拥有这些文件)。

请注意,在设置过程中,您可以更改 ReleaseSetupData 对象上的 ImageType 属性,然后 Copy 方法将使用所述格式(0 = 多页 TIFF , CCITT G4).

// binary image
DocumentData.ImageFiles.Copy(Path.GetTempPath(), -1);
string tmpFile = Path.Combine(Path.GetTempPath(), DocumentData.UniqueDocumentID.ToString("X8")) + Path.GetExtension(ImageFileNames[0]);
if (File.Exists(tmpFile))
{
    // assuming BinaryImage is of type byte[]
    BinaryImage = File.ReadAllBytes(tmpFile);
    File.Delete(tmpFile);
}

// binary PDF
if (File.Exists(DocumentData.KofaxPDFFileName))
{
    // assuming BinaryPdf is of type byte[]
    BinaryPdf = File.ReadAllBytes(DocumentData.KofaxPDFFileName);
}