示例#1
0
        static void RecognizePdf2SearchableFromContent(Configuration conf)
        {
            string name = "TheCall.pdf";

            using (FileStream fs = File.OpenRead(name))
            {
                OcrApi api     = new OcrApi(conf);
                var    request = new OCRRequestData()
                {
                    DsrMode = DsrMode.NoDsrNoFilter, ResultType = ResultType.Pdf, Language = LanguageEnum.Arabic
                };
                OCRPDFResponse response = api.OcrPdfFromContent(request, fs);
                File.WriteAllBytes(@"result.pdf", Convert.FromBase64String(response.ResultData[0].ImageOcrResults.First().ResultPdf));
            }
        }
示例#2
0
        /// <summary>
        /// Recognize Receipt image located at Aspose Storage.
        /// Use StorageApi to upload your files. <see cref="StorageApi"/>
        /// </summary>
        /// <param name="requestData">PDF recognition configuration <see cref="OCRRequestData"/></param>
        /// <returns><see cref="OCRPDFResponse"/></returns>
        public OCRPDFResponse OcrPdfFromStorage(OCRRequestDataStorage requestData)
        {
            var requestUrl = BuildUrl("recognize-pdf-storage");
            var formParams = new Dictionary <string, object> {
                { "requestData", requestData }
            };

            try
            {
                return(this.apiInvoker.InvokeApi <OCRPDFResponse>(requestUrl, "POST", null, null, formParams));
            }
            catch (TimeoutException)
            {
                OCRPDFResponse ocrRespose = new OCRPDFResponse();
                ocrRespose.Status        = "2";
                ocrRespose.StatusMessage = "TimeOutException";
                return(ocrRespose);
            }
        }
示例#3
0
        /// <summary>
        /// Recognize Receipt image from File Stream
        /// </summary>
        /// <param name="requestData">PDF recognition configuration <see cref="OCRRequestData"/></param>
        /// <param name="file">Local file stream</param>
        /// <returns><see cref="OCRPDFResponse"/></returns>
        public OCRPDFResponse OcrPdfFromContent(OCRRequestData requestData, Stream file)
        {
            var requestUrl = BuildUrl("recognize-pdf-content");
            var fileInfo   = this.apiInvoker.ToFileInfo(file, "File");
            var formParams = new Dictionary <string, object> {
                { "file", fileInfo }, { "requestData", requestData }
            };

            try
            {
                return(this.apiInvoker.InvokeApi <OCRPDFResponse>(requestUrl, "POST", null, null, formParams));
            }
            catch (TimeoutException)
            {
                OCRPDFResponse ocrRespose = new OCRPDFResponse();
                ocrRespose.Status        = "2";
                ocrRespose.StatusMessage = "TimeOutException";
                return(ocrRespose);
            }
        }
示例#4
0
        static string RecognizePdfFromContent(Configuration conf)
        {
            string name = "TheCall.pdf";

            using (FileStream fs = File.OpenRead(name))
            {
                OcrApi api     = new OcrApi(conf);
                var    request = new OCRRequestData()
                {
                    DsrMode = DsrMode.NoDsrNoFilter
                };
                OCRPDFResponse response = api.OcrPdfFromContent(request, fs);

                var all_text = response.ResultData.Aggregate(
                    "", (s, page) =>
                    s += page.OriginalText + "\n\n" + page.ImageOcrResults.Aggregate("", (s1, singleImageResult) => s1 += singleImageResult.ResultText + "\n\n") + "\n\n");

                return(all_text);
            }
        }