1

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;
        }
    }
  • It is currently unclear what the problem is. You have both the filename and byte array in the code shown. – Nkosi Dec 03 '18 at 08:28
  • Your question is not clear to me either. What do you mean with "only a way to extract the name and the byte array from the document"? – johey Dec 03 '18 at 09:22
  • sorry, I wanted to sum up the following: Within my ReleaseDoc method I want to convert the incoming document to a byte array. –  Dec 03 '18 at 09:27
  • I updated my code maybe things get more clear –  Dec 03 '18 at 09:54

1 Answers1

-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);
}
Wolfgang Radl
  • 2,319
  • 2
  • 17
  • 22
  • thanks for your reply, my first question: should I replace `ImageFileNames[0]` with `documentData.ImageFiles[0].FileName` ? I think that this should be the code https://pastebin.com/y32R8Pai no? –  Dec 04 '18 at 08:07
  • Sorry, I forgot to mention that `ImageFileNames` is a simple collection of strings (file names for each image in the `ImageFiles` collection), so `documentData.ImageFiles[0].FileName`essentially achieves the same thing. – Wolfgang Radl Dec 04 '18 at 13:52
  • thanks for your reply. This should be worth the bounty :) –  Dec 04 '18 at 14:55