Symptoms
Error when importing documents of Office format via FlexiCapture Web API:
The Image File Format Has not been recognized
Cause
Incorrect API call.
Resolution
Here are some troubleshooting steps:
- Make sure that Processing of Office documents is enabled inside Batch Type Properties:
- To process MS office documents, MS office has to be installed on the server. If authentication is required for MS office, supply the credentials under the Import profile > Image processing > Authentication.
- To ensure the cause lays in the code, set up and trigger the Hot Folder import for the particular document: Image import profiles.
- If the Hot Folder import and further recognition succeed then it's a code-base issue and the code must be reviewed. Here is the code sample for Office documents import via FlexiCapture 12 API:
using System;
using System.IO;
using System.Linq;
using System.Net;
namespace OfficeDocumentsVSwebAPI
{
class Program
{
static void Main(string[] args)
{
string endpoint = "http://127.0.0.1";
string tenant = "";
string projectName = "Invoice Processing (AU)";
string path = @"C:\Clients\ARM IT Group\3521-Anglican.docx";
//Open session
var _client = new FlexiCapture.FlexiCaptureWebServiceApiVersion1();
tenant = !string.IsNullOrEmpty(tenant)
? $"?Tenant={tenant}"
: string.Empty;
_client.Url = $"{endpoint}/FlexiCapture12/Server/API/v1/Soap{tenant}";
_client.Credentials = CredentialCache.DefaultCredentials;
int _sessionId = _client.OpenSession(10, 12);
//Get project
var project = _client.GetProjects()
?.FirstOrDefault(item => item.Name.Equals(projectName, StringComparison.InvariantCultureIgnoreCase))
?? throw new ArgumentException($"The server has no project '{projectName}'.");
var batch = new FlexiCapture.Batch()
{
Name = "Test " + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"),
BatchTypeId = 0
};
//Create a new batch
int batchId = _client.AddNewBatch(_sessionId, project.Id, batch, 0);
//Upload document
_client.OpenBatch(_sessionId, batchId);
using (var stream = File.Open(path, FileMode.Open, FileAccess.Read))
{
FlexiCapture.File file = new FlexiCapture.File
{
Name = Path.GetFileName(path),
Bytes = new byte[stream.Length]
};
stream.Read(file.Bytes, 0, file.Bytes.Length);
_client.AddNewImage(_sessionId, batchId, file);
}
_client.CloseBatch(_sessionId, batchId);
//Start recognition
_client.ProcessBatch(_sessionId, batchId);
}
}
}
Comments
0 comments
Please sign in to leave a comment.