您也可以使用 Abbyy FC Web API。您必须在简单工作流模式下设置项目。
使用 Web API生成sessionId
andbatchId
并将文档上传到 Abbyy 后,您可以使用以下代码识别文档并获取nextstage
and taskId
。
public enum eProcessingStageTypes
{
Scanning = 100,
Rescanning = 150,
Recognition = 200,
UnattendedProcessing = 250,
DocumentAssemblyCheck = 300,
DataVerificationPreprocessing = 390,
DataVerification = 400,
DataVerificationPostprocessing = 410,
VerificationPreprocessing = 490,
Verification = 500,
VerificationPostprocessing = 510,
BatchIntegrityCheck = 600,
ExportConfirmation = 700,
ExportPrerecognitionforexporttoPDFsearchable = 780,
Export = 800,
Training = 850,
Userrequestsprocessing = 950,
Processed = 900,
Exceptions = 1000,
VerificationVerificationPreprocessing = 2001,
VerificationVerificationPostprocessing = 2002,
UnknownStage = -1,
Failed = -2,
NextStage = -3
};
int projId = 0;
int roleId = 0;
int sessionId = 0;
int batchId = 0;
int roleType = 0;
int stationType = 0;
string guid = String.Empty;
//guid = Guid of Project on Abbyy FC
//roleType - https://help.abbyy.com/en-us/flexicapture/12/developer/troletype
//stationType - https://help.abbyy.com/en-us/flexicapture/12/developer/stationtypeenum
sessionId = fcSvcObj.OpenSession(roleType, stationType);
projectId = fcSvcObj.OpenProject(sessionId, guid);
batchId = fcSvcObj.AddNewBatch(sessionId, projectId, batch, 0);
fcSvcObj.ProcessBatch(sessionId, batchId);
Stopwatch stopWatch = new Stopwatch();
currBatch = new Batch();
DateTime startTime = DateTime.Now;
var percentCompleted = 0;
double timeOut = 60;
double elapsedTime = 0.0;
stopWatch.Start();
while (percentCompleted < 100 && elapsedTime < timeOut && currBatch.StageExternalId < (int)eProcessingStageTypes.Recognition)
{
percentCompleted = fcSvcObj.GetBatchPercentCompleted(batchId);
currBatch = fcSvcObj.GetBatch(batchId);
System.Threading.Thread.Sleep(500);
elapsedTime = DateTime.Now.Subtract(startTime).TotalSeconds;
}
stopWatch.Stop();
stopWatch.Reset();
if (percentCompleted < 100 && elapsedTime > timeOut)
{
throw new Exception("Timeout Error. Processing was not completed within maximum timeout provided.");
}
//Document has moved to Exceptions
if (currBatch.StageExternalId == (int)eProcessingStageTypes.Exceptions)
{
throw new Exception("Document moved to exceptions");
}
//Document requires manual verification
if (currBatch.StageExternalId == (int)eProcessingStageTypes.Verification || currBatch.StageExternalId == (int)eProcessingStageTypes.DataVerification)
{
TaskList tasks = fcSvcObj.GetAvailableTasks(sessionId, projId, 500, false);
int taskId = tasks.Where(task => task.BatchId == batchId).FirstOrDefault().Id;
// Generate Verification URL
string verificationUrl = "http://servername/FlexiCapture12/Verification/Verify?projectId=<pid>&roleId=<rid>&taskId=<tid>&returnTo=DeadEnd&mode=mini";
verificationUrl.Replace("<pid>",projectId).Replace("<rid>",roleId).Replace("<tid",taskId);
}
// Document is ready for export
if (currBatch.StageExternalId == (int)eProcessingStageTypes.Processed)
{
//Code to Export Documents
}
发布后,您可以导航到 Abbyy 上的 Web 验证站以执行手动验证。验证URL可以在上面的代码中生成。
验证后,文件已准备好导出,您可以使用以下代码执行文件导出。
您需要保存sessionId
和batchId
从处理的第一部分导出文档。您也可以使用新会话,但请确保在流程的第一部分关闭会话。
string outputFolderPath = "DestinationFolder";
bool isBatchOpen = fcSvcObj.OpenBatch(sessionId, batchId);
if (isBatchOpen)
{
documents documents = fcSvcObj.GetDocuments(sessionId, batchId);
if (documents == null) return;
foreach (Document document in documents)
{
if (document.Id > 0)
{
fileNames fns = fcSvcObj.GetDocumentResultsList(sessionId, batchId, document.Id);
if (fns != null)
{
foreach (string fn in fns)
{
FCWebSvc.File file = fcSvcObj.LoadDocumentResult(sessionId, batchId, document.Id, fn);
System.IO.File.WriteAllBytes(outputFolderPath + Path.GetFileName(fn), file.Bytes);
}
}
}
}
}