【问题标题】:convert Kofax Release document to binary将 Kofax Release 文档转换为二进制文件
【发布时间】:2018-11-28 09:29:06
【问题描述】:

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

用户可以在ReleaseSetup 中设置一个布尔值,这会导致“如果您必须在多种文件类型之间做出决定,请使用 PDF 文件”。

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

如何检查我是否必须在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;
        }
    }

【问题讨论】:

  • 目前还不清楚是什么问题。您在显示的代码中同时拥有文件名和字节数组。
  • 你的问题我也不清楚。 “只有一种从文档中提取名称和字节数组的方法”是什么意思?
  • 对不起,我想总结一下:在我的 ReleaseDoc 方法中,我想将传入的文档转换为字节数组。
  • 我更新了我的代码,也许事情会变得更清楚

标签: c# kofax


【解决方案1】:

不要手动合并 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);
}

【讨论】:

  • 感谢您的回复,我的第一个问题:我应该将ImageFileNames[0] 替换为documentData.ImageFiles[0].FileName 吗?我认为这应该是代码pastebin.com/y32R8Pai 否?
  • 抱歉,我忘了提ImageFileNames 是一个简单的字符串集合(ImageFiles 集合中每个图像的文件名),所以documentData.ImageFiles[0].FileName本质上实现了同样的事情。跨度>
  • 感谢您的回复。这应该值得赏金:)
猜你喜欢
  • 1970-01-01
  • 2013-08-20
  • 1970-01-01
  • 2010-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-07
  • 1970-01-01
相关资源
最近更新 更多