public void SaveOCRBlob(OcrAttchmentModel ocrAttModel, string fileName, Byte[] sbytes, bool isNotPdf = false)
 {
     using (var client = new HttpClient())
     {
         string ApiKey  = ConfigurationManager.AppSettings["ApiKey"];
         string baseUrl = ConfigurationManager.AppSettings["BaseUrl"];
         client.BaseAddress = new Uri(baseUrl);
         client.DefaultRequestHeaders.Clear();
         client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
         client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
         client.DefaultRequestHeaders.TryAddWithoutValidation("ApiKey", ApiKey);
         LogUtility.WriteToFile("OCR Process Request PayLoad Header:" + client.DefaultRequestHeaders);
         //HTTP POST
         OcrBlobModel ocrBlobModel = new OcrBlobModel();
         ocrBlobModel.ridAttachment = Convert.ToInt32(ocrAttModel.ridAttachment);
         ocrBlobModel.contents      = isNotPdf == true ? new TextExtractor().Extract(sbytes).Text : Encoding.UTF8.GetString(sbytes, 0, sbytes.Length);
         string strPayload = JsonConvert.SerializeObject(ocrBlobModel);
         LogUtility.WriteToFile("OCR Process Request PayLoad:" + strPayload);
         HttpContent c     = new StringContent(strPayload, Encoding.UTF8, "application/json");
         string      path1 = client.BaseAddress + "Attachment/CreateOCREntry";
         //ConfigurationManager.AppSettings["CreateOCR"];
         HttpResponseMessage response = client.PostAsync(path1, c).Result;
         LogUtility.WriteToFile("OCR Process Response:" + response);
     }
 }
 public void GenerateByteArray(OcrAttchmentModel ocrAttModel, string sourcePath, string fileName)
 {
     byte[] sbytes = null;
     sbytes = File.ReadAllBytes(ocrAttModel.documentumid);
     if (sbytes != null && sbytes.Length > 0)
     {
         SaveOCRBlob(ocrAttModel, fileName, sbytes, true);
     }
 }
        public void GenerateOCR(OcrAttchmentModel ocrAttModel, string sourcePath, string fileName)  //, string targetPath
        {
            byte[] sbytes         = null;
            string languageFolder = ConfigurationManager.AppSettings["Tessdata"];

            LogUtility.WriteToFile("OCR Utility Process Path:" + languageFolder);
            //m_strCurrentDirectory + ConfigurationManager.AppSettings["Tessdata"];     // "\\OCR\\tessdata";
            m_Tesseract              = new Tesseract(m_StrProductKey);
            m_ImageCore              = new ImageCore();
            m_PDFRasterizer          = new PDFRasterizer(m_StrProductKey);
            tempListSelectedBitmap   = new List <System.Drawing.Bitmap>();
            m_Tesseract.TessDataPath = languageFolder;
            m_Tesseract.Language     = languages["English"];
            m_Tesseract.ResultFormat = ResultFormat.Text;

            string imageFolder = sourcePath;
            string testPath    = string.Empty;

            if (sourcePath.Contains(".pdf"))
            {
                m_PDFRasterizer.ConvertMode = Dynamsoft.PDF.Enums.EnumConvertMode.enumCM_AUTO;
                m_PDFRasterizer.ConvertToImage(imageFolder, "", 200, this as IConvertCallback);
            }
            else
            {
                m_ImageCore.IO.LoadImage(imageFolder);
            }
            int          imgCount  = m_ImageCore.ImageBuffer.HowManyImagesInBuffer;
            List <short> lstindexs = new List <short>();

            for (short index = 0; index < imgCount; index++)
            {
                if (index >= 0 && index < m_ImageCore.ImageBuffer.HowManyImagesInBuffer)
                {
                    if (tempListSelectedBitmap == null)
                    {
                        tempListSelectedBitmap = new List <Bitmap>();
                    }
                    Bitmap temp = m_ImageCore.ImageBuffer.GetBitmap(index);
                    tempListSelectedBitmap.Add(temp);
                    lstindexs.Add(index);
                }
            }

            if (tempListSelectedBitmap != null)
            {
                sbytes = m_Tesseract.Recognize(tempListSelectedBitmap);
            }

            if (sbytes != null && sbytes.Length > 0)
            {
                LogUtility.WriteToFile("OCR Processing File Name:" + fileName);
                SaveOCRBlob(ocrAttModel, fileName, sbytes);
            }
        }
 public void SaveOCRWithoutContent(OcrAttchmentModel ocrAttModel)
 {
     using (var client = new HttpClient())
     {
         string ApiKey  = ConfigurationManager.AppSettings["ApiKey"];
         string baseUrl = ConfigurationManager.AppSettings["BaseUrl"];
         client.BaseAddress = new Uri(baseUrl);
         client.DefaultRequestHeaders.Clear();
         client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
         client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
         client.DefaultRequestHeaders.TryAddWithoutValidation("ApiKey", ApiKey);
         //HTTP POST
         OcrBlobModel ocrBlobModel = new OcrBlobModel();
         ocrBlobModel.ridAttachment = Convert.ToInt32(ocrAttModel.ridAttachment);
         ocrBlobModel.contents      = " ";
         string      strPayload = JsonConvert.SerializeObject(ocrBlobModel);
         HttpContent c          = new StringContent(strPayload, Encoding.UTF8, "application/json");
         string      path1      = client.BaseAddress + "Attachment/CreateOCREntry";
         //ConfigurationManager.AppSettings["CreateOCR"];
         HttpResponseMessage response = client.PostAsync(path1, c).Result;
     }
 }