When it comes to the Kofax Release I want to convert each scanned document to a byte array. Within my ReleaseDoc
method I first want to check if the file is a PDF file or TIFF file.
The user is able to setup a bool value in the ReleaseSetup
that leads to 'use PDF file if you have to decide between multiple file types'.
I just created a snipped that tries to convert the file to a byte array.
How can I check if I have to use a PDF or a image file within my ReleaseDoc
method?
It doesn't matter if the PDF file has three pages because it is a single file. But it matters if there are three TIFF files that need to get converted to one byte array. How can I achieve this?
To sum up I need within my method only a way to extract the name and the byte array from the document.
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;
}
}
Don't merge TIFFs manually. That's what the
Copy
method on theImageFiles
collection is for. Here's a short example - you will end up with two byte arrays,BinaryImage[]
andPdfImage[]
. During release, just check for null before attempting to write PDFs (if the PDF Generator wasn't added to the queue, you just won't have those files).Note that during setup you may change the
ImageType
property on theReleaseSetupData
object, and theCopy
method will then use said format (0 = multipage TIFF, CCITT G4).