convert Kofax Release document to binary

∥☆過路亽.° 提交于 2019-12-24 11:46:53

问题


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;
        }
    }

回答1:


Don't merge TIFFs manually. That's what the Copy method on the ImageFiles collection is for. Here's a short example - you will end up with two byte arrays, BinaryImage[] and PdfImage[]. 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 the ReleaseSetupData object, and the Copy method will then use said format (0 = multipage 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);
}


来源:https://stackoverflow.com/questions/53516159/convert-kofax-release-document-to-binary

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!