关于Kofax发行版,我想将每个扫描的文档转换为字节数组。首先,我要使用ReleaseDoc
方法来检查文件是PDF文件还是TIFF文件。
用户可以在ReleaseSetup
中设置bool值,从而导致“如果您必须在多种文件类型之间做出决定,则使用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;
}
}
答案 0 :(得分:0)
不要手动合并TIFF。这就是Copy
集合上的ImageFiles
方法的用途。这是一个简短的示例-您将得到两个字节数组BinaryImage[]
和PdfImage[]
。在发行期间,只需尝试检查是否为空,然后再尝试编写PDF(如果未将PDF Generator添加到队列中,那么您将没有这些文件)。
请注意,在设置过程中,您可以更改ImageType
对象上的ReleaseSetupData
属性,然后Copy
方法将使用所述格式(0 =多页TIFF,CCITT G4)。 / p>
// 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);
}