convert Kofax Release document to binary












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









share|improve this question

























  • It is currently unclear what the problem is. You have both the filename and byte array in the code shown.

    – Nkosi
    Dec 3 '18 at 8: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 3 '18 at 9:22













  • sorry, I wanted to sum up the following: Within my ReleaseDoc method I want to convert the incoming document to a byte array.

    – MHComputech
    Dec 3 '18 at 9:27











  • I updated my code maybe things get more clear

    – MHComputech
    Dec 3 '18 at 9:54
















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









share|improve this question

























  • It is currently unclear what the problem is. You have both the filename and byte array in the code shown.

    – Nkosi
    Dec 3 '18 at 8: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 3 '18 at 9:22













  • sorry, I wanted to sum up the following: Within my ReleaseDoc method I want to convert the incoming document to a byte array.

    – MHComputech
    Dec 3 '18 at 9:27











  • I updated my code maybe things get more clear

    – MHComputech
    Dec 3 '18 at 9:54














1












1








1


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









share|improve this question
















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






c# kofax






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 3 '18 at 9:53







MHComputech

















asked Nov 28 '18 at 9:29









MHComputechMHComputech

164114




164114













  • It is currently unclear what the problem is. You have both the filename and byte array in the code shown.

    – Nkosi
    Dec 3 '18 at 8: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 3 '18 at 9:22













  • sorry, I wanted to sum up the following: Within my ReleaseDoc method I want to convert the incoming document to a byte array.

    – MHComputech
    Dec 3 '18 at 9:27











  • I updated my code maybe things get more clear

    – MHComputech
    Dec 3 '18 at 9:54



















  • It is currently unclear what the problem is. You have both the filename and byte array in the code shown.

    – Nkosi
    Dec 3 '18 at 8: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 3 '18 at 9:22













  • sorry, I wanted to sum up the following: Within my ReleaseDoc method I want to convert the incoming document to a byte array.

    – MHComputech
    Dec 3 '18 at 9:27











  • I updated my code maybe things get more clear

    – MHComputech
    Dec 3 '18 at 9:54

















It is currently unclear what the problem is. You have both the filename and byte array in the code shown.

– Nkosi
Dec 3 '18 at 8:28





It is currently unclear what the problem is. You have both the filename and byte array in the code shown.

– Nkosi
Dec 3 '18 at 8: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 3 '18 at 9:22







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 3 '18 at 9:22















sorry, I wanted to sum up the following: Within my ReleaseDoc method I want to convert the incoming document to a byte array.

– MHComputech
Dec 3 '18 at 9:27





sorry, I wanted to sum up the following: Within my ReleaseDoc method I want to convert the incoming document to a byte array.

– MHComputech
Dec 3 '18 at 9:27













I updated my code maybe things get more clear

– MHComputech
Dec 3 '18 at 9:54





I updated my code maybe things get more clear

– MHComputech
Dec 3 '18 at 9:54












1 Answer
1






active

oldest

votes


















0





+100









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





share|improve this answer
























  • 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 pastebin.com/y32R8Pai no?

    – MHComputech
    Dec 4 '18 at 8: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].FileNameessentially achieves the same thing.

    – Wolfgang Radl
    Dec 4 '18 at 13:52











  • thanks for your reply. This should be worth the bounty :)

    – MHComputech
    Dec 4 '18 at 14:55











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53516159%2fconvert-kofax-release-document-to-binary%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0





+100









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





share|improve this answer
























  • 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 pastebin.com/y32R8Pai no?

    – MHComputech
    Dec 4 '18 at 8: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].FileNameessentially achieves the same thing.

    – Wolfgang Radl
    Dec 4 '18 at 13:52











  • thanks for your reply. This should be worth the bounty :)

    – MHComputech
    Dec 4 '18 at 14:55
















0





+100









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





share|improve this answer
























  • 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 pastebin.com/y32R8Pai no?

    – MHComputech
    Dec 4 '18 at 8: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].FileNameessentially achieves the same thing.

    – Wolfgang Radl
    Dec 4 '18 at 13:52











  • thanks for your reply. This should be worth the bounty :)

    – MHComputech
    Dec 4 '18 at 14:55














0





+100







0





+100



0




+100





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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 3 '18 at 20:14









Wolfgang RadlWolfgang Radl

1,27321115




1,27321115













  • 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 pastebin.com/y32R8Pai no?

    – MHComputech
    Dec 4 '18 at 8: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].FileNameessentially achieves the same thing.

    – Wolfgang Radl
    Dec 4 '18 at 13:52











  • thanks for your reply. This should be worth the bounty :)

    – MHComputech
    Dec 4 '18 at 14:55



















  • 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 pastebin.com/y32R8Pai no?

    – MHComputech
    Dec 4 '18 at 8: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].FileNameessentially achieves the same thing.

    – Wolfgang Radl
    Dec 4 '18 at 13:52











  • thanks for your reply. This should be worth the bounty :)

    – MHComputech
    Dec 4 '18 at 14:55

















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 pastebin.com/y32R8Pai no?

– MHComputech
Dec 4 '18 at 8:07







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 pastebin.com/y32R8Pai no?

– MHComputech
Dec 4 '18 at 8: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].FileNameessentially achieves the same thing.

– Wolfgang Radl
Dec 4 '18 at 13:52





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].FileNameessentially achieves the same thing.

– Wolfgang Radl
Dec 4 '18 at 13:52













thanks for your reply. This should be worth the bounty :)

– MHComputech
Dec 4 '18 at 14:55





thanks for your reply. This should be worth the bounty :)

– MHComputech
Dec 4 '18 at 14:55




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53516159%2fconvert-kofax-release-document-to-binary%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks