public string documentReader(COB_ParseType stepId, string fileSource, string extension, int appId, string modelData) { string returnExpression = string.Empty; IDocProcess docProcess = null; try { switch (stepId) { case COB_ParseType.TradeLicense: docProcess = new CPTradeLicenceProcessing(); break; case COB_ParseType.Passport: docProcess = new PassportProcessing(); break; case COB_ParseType.EmiratesId: docProcess = new EmiratesIDProcessing(); break; //case COB_ParseType.MOA: // docProcess = new MOAProcessing(); break; case COB_ParseType.SHTradeLicense: docProcess = new SHTradeLicenceProcessing(); break; default: throw new NotImplementedException(); } returnExpression = docProcess.ReadProcessing(fileSource, extension, appId, modelData); } catch (Exception ex) { /*throw ex*/; //Global.Logger.Error(ex); return(ex.ToString()); } return(returnExpression); }
private List <LineData> ProcessDocument(COB_ParseType stepId, string sourceFile, string extension) { List <LineData> lines = new List <LineData>(); using (Ocr ocr = new Ocr(GetConfigResource())) { try { var preProcessor = Configure(ocr); switch (extension.ToLower()) { case ".jpg": case ".jpeg": case ".png": case ".bmp": ocr.ReadJPEGSource(sourceFile); break; case ".tif": case ".tiff": ocr.ReadTIFFSource(sourceFile); break; case ".pdf": //ocr.EnablePdfOutput = true; //ocr.EnableTextOutput = false; ocr.EndPage = 2; //process only 2 pages as currently nothing is being read from 3rd page ocr.ReadPDFSource(sourceFile); break; } if (stepId == COB_ParseType.TradeLicense) { preProcessor.ForceTableZones = true; } if (!ocr.Recognize(preProcessor)) { if (ocr.LastException == null) { throw new Exception("Unable to parse document"); } else { throw ocr.LastException; } } for (int i = 1; i <= ocr.NumberPages && i <= ocr.EndPage; i++) { var pageLines = ocr.ReadPageLines(i); if (pageLines?.Count > 0) { lines.AddRange(pageLines); } } } catch (Exception) { throw; } finally { try { File.Copy(ocr.LogFilePath, Path.Combine(logsPath, Path.GetFileNameWithoutExtension(sourceFile) + ".log")); } catch (Exception exp) { } ocr.DeleteTemporaryFiles(); } } return(lines); }
public string getValuesbyStepId(COB_ParseType stepId, string sourceFile, string extension) { string result = string.Empty; using (Ocr ocr = new Ocr(GetConfigResource())) { try { var preProcessor = Configure(ocr); if (stepId == COB_ParseType.EmiratesId) { using (Bitmap map = new Bitmap(sourceFile)) { //using (var img = Helper.ConvertBlackWhiteImage(map)) { var img = map; //Helper.SetContrast(img, 80); ocr.ReadImageSource(img); if (ocr.Recognize(preProcessor)) { result = this.getValuesByEid(ocr); } else { if (ocr.LastException == null) { throw new Exception("Unable to parse document"); } else { throw ocr.LastException; } } } } } else { switch (extension.ToLower()) { case ".jpg": case ".jpeg": case ".png": case ".bmp": ocr.ReadJPEGSource(sourceFile); break; case ".tif": case ".tiff": ocr.ReadTIFFSource(sourceFile); break; case ".pdf": //ocr.EnablePdfOutput = true; //ocr.EnableTextOutput = false; ocr.EndPage = 2; //process only 2 pages as currently nothing is being read from 3rd page ocr.ReadPDFSource(sourceFile); break; } if (stepId == COB_ParseType.TradeLicense) { preProcessor.ForceTableZones = true; } if (!ocr.Recognize(preProcessor)) { if (ocr.LastException == null) { throw new Exception("Unable to parse document"); } else { throw ocr.LastException; } } switch (stepId) { case COB_ParseType.TradeLicense: var licenseLines = new List <LineData>(); for (int i = 1; i <= ocr.NumberPages && i <= ocr.EndPage; i++) { var pageLines = ocr.ReadPageLines(i); if (pageLines?.Count > 0) { licenseLines.AddRange(pageLines); } } // currently 'dubai' is hardcoded, required changes to fetch it from Application result = TradeLicenseParserFactory.Parse(licenseLines, "DUBAIECONOMY", "LLC"); break; case COB_ParseType.Passport: StringBuilder build = new StringBuilder(); for (int pageNo = 0; pageNo < ocr.NumberPages; pageNo++) { var lines = ocr.ReadPageLines(pageNo + 1); if (lines?.Count > 0) { int i = 0; for (i = 0; i < lines.Count; i++) { Regex re = new Regex(@"(P|V|C)(<|«)(.*)"); if (re.IsMatch(lines[i].LineWords)) { break; } } int counti = 0; while (i < lines.Count && counti < 2) //only two lines to be read as passport has only two line MRZ as per standard { string temp = lines[i].LineWords; temp = temp.TrimEnd().Replace("«", "<<").Replace("&", "<").Replace("\n", "").Replace(" ", ""); temp = System.Text.RegularExpressions.Regex.Replace(temp, "[']+", ""); if (counti == 0) { temp = Regex.Replace(temp, ".*P<", "P<"); } temp = temp.Substring(0, Math.Min(temp.Length, 44)); temp = temp.PadRight(44, '<'); build.Append(temp); i++; } } } result = build.ToString(); MRZParser pareser = new MRZParser(); result = pareser.Parse(result); break; case COB_ParseType.EmiratesId: result = getValuesByEid(ocr); break; default: return(string.Empty); } } } catch (Exception exp) { throw; } finally{ try { File.Copy(ocr.LogFilePath, Path.Combine(logsPath, Path.GetFileNameWithoutExtension(sourceFile) + ".log")); } catch (Exception exp) { } ocr.DeleteTemporaryFiles(); } } return(result); }