コード例 #1
0
ファイル: OCRTest.cs プロジェクト: buyonlinemahi/AR
        public void Add_OCRRecord()
        {
            DLModel.OcrId       = 1;
            DLModel.OcrFileName = "OCR1.pdf";
            DLModel.CreatedBy   = 1;
            DLModel.CreatedOn   = System.DateTime.Now;
            DLModel.IsDeleted   = null;
            DLModel.DeletedBy   = null;
            DLModel.DeletedOn   = null;
            int OcrId = _IOCRImplBL.AddOCRRecord(DLModel);

            Assert.IsTrue(true, "Unable to find");
        }
コード例 #2
0
        public ActionResult UploadOCRFile(HttpPostedFileBase uploadOCRFile)
        {
            string result = GlobalConst.ConstantChar.Blank;

            try
            {
                OCRModel           ocrModel = new OCRModel();
                HttpPostedFileBase File     = Request.Files[GlobalConst.ConstantChar.UploadOCRFile];
                bool   r       = _storageServices.CreateOCRUploadFolder(Server.MapPath(ConfigurationManager.AppSettings[GlobalConst.ConstantChar.StoragePath]), GlobalConst.ConstantChar.OCRUploads);
                string OCRPath = Server.MapPath(ConfigurationManager.AppSettings[GlobalConst.ConstantChar.StoragePath].ToString()) + GlobalConst.ConstantChar.DoubleSlash +
                                 GlobalConst.ConstantChar.OCRUploads + GlobalConst.ConstantChar.DoubleSlash;

                string OCRFilePath = OCRPath + Path.GetFileName(uploadOCRFile.FileName);
                File.SaveAs(OCRFilePath);
                Reader bc = new Reader();
                bc.RegistrationKey           = WebConfigurationManager.AppSettings[GlobalConst.ConstantChar.BarCodeKey];
                bc.RegistrationName          = WebConfigurationManager.AppSettings[GlobalConst.ConstantChar.BarCodeKeyName];
                bc.BarcodeTypesToFind.Code39 = true;

                iTextSharp.text.pdf.PdfReader reader = null;
                reader = new iTextSharp.text.pdf.PdfReader(OCRFilePath);
                FoundBarcode[] barcodes = bc.ReadFrom(OCRFilePath).Where(val => val.Value == GlobalConst.ConstantChar.BarCodeCHECK).ToArray();

                int i = 0;
                for (i = 0; i <= barcodes.Length - 1; i++)
                {
                    string   newOCRfileName = Guid.NewGuid().ToString() + GlobalConst.Extension.PDF;
                    string   newOCRfilepath = OCRPath + newOCRfileName;
                    string[] barcodename1   = barcodes[i].Value.Split(GlobalConst.ConstantChar.RoundBracketStart);
                    string   barcodename    = barcodename1[0];
                    int      pagenoE        = 0;
                    int      pagenoS        = barcodes[i].Page; //page starting
                    bool     flag           = false;

                    if (i == barcodes.Length - 1)
                    {
                        pagenoE = reader.NumberOfPages;
                    }
                    else
                    {
                        int num = 1;
                        while (flag == false)
                        {
                            if (i + num < barcodes.Length)
                            {
                                if (barcodename == GlobalConst.ConstantChar.BarCodeCHECK)
                                {
                                    pagenoE = barcodes[i + num].Page;
                                    flag    = true;
                                }
                            }
                            else
                            {
                                flag    = true;
                                pagenoE = reader.NumberOfPages;
                            }
                            num = num + 1;
                        }
                    }

                    if (barcodename == GlobalConst.ConstantChar.BarCodeCHECK)
                    {
                        ocrModel.OcrFileName = newOCRfileName;
                        ocrModel.CreatedBy   = Convert.ToInt32(Request.Cookies[GlobalConst.SessionKeys.userDetailMgmt].Values[GlobalConst.SessionKeys.userID]);
                        ocrModel.CreatedOn   = DateTime.Now;
                        _ocr.AddOCRRecord(Mapper.Map <LMGEDI.Core.Data.Model.OCR>(ocrModel));
                        ExtractPage(OCRFilePath, newOCRfilepath, pagenoS + 1, pagenoE - 1);
                        result = GlobalConst.ConstantChar.True;
                    }
                }

                reader.Dispose();
                System.IO.File.Delete(OCRFilePath);
            }
            catch (Exception ex)
            {
                _arCommonService.CreateErrorLog(ex.Message, ex.StackTrace);
            }
            return(Json(result));
        }