logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Akshara  
#1 Posted : Thursday, July 13, 2017 11:48:33 PM(UTC)
Akshara

Rank: Member

Groups: Registered
Joined: 2/7/2017(UTC)
Posts: 12
India
Location: Pune

Hey Paul,

I am getting an error while doing OCR on PDF. while extracting the data I am getting an error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt". Can you tell me solution regarding this issue. I am getting this error in following line:-
string text = ocrApi.GetTextFromImage(bitmap.Image as Bitmap, rect);
I want the solution Asap.


Code is:

Code:

 InitWebApp();
            OcrApi.LicenseKey = ConfigurationManager.AppSettings["LicenseKeyOcr"];
            var ocr = OcrApi.Create();
            MapperController mapperController = new MapperController();

            double scaleFactor = 2;
            foreach (var item in selChkList)

{
                using (var doc = PdfDocument.Load(item))
                {
                    List<Ocr> tempMetadata = mapperController.GetOcrMetadata(pdfTemplateId);
                    Dictionary<string, string> ocrTemp = new Dictionary<string, string>();
                    foreach (var itemdata in tempMetadata)
                    {
                        switch (itemdata.Language)
                        {
                            case "English":
                                ocr.Init(Languages.English);
                                break;
                            case "Hindi":
                                ocr.Init(Languages.Hindi);
                                break;
                            case "Marathi":
                                ocr.Init(Languages.Maharashtra);
                                break;

                            default:
                                break;
                        }
                        for (int i = 0; i < doc.Pages.Count; i++)
                        {
                            using (var page = doc.Pages[i])
                            {
                                string text = null;
                                if (doc.Pages[i] == doc.Pages[itemdata.PageIndex])
                                {
                                    int width = (int)(page.Width * scaleFactor);
                                    int height = (int)(page.Height * scaleFactor);
                                    using (var bitmap = new PdfBitmap(width, height, true))
                                    {
                                        var lefttopCorner = page.PageToDevice(0, 0, (int)(page.Width), (int)(page.Height), PageRotate.Normal, itemdata.Left, itemdata.Top);
                                        var rightbottomcorner = page.PageToDevice(0, 0, (int)(page.Width), (int)(page.Height), PageRotate.Normal, itemdata.Right, itemdata.Bottom);
                                        page.Render(bitmap, 0, 0, bitmap.Width, bitmap.Height, PageRotate.Normal, RenderFlags.FPDF_LCD_TEXT);
                                        var rect = new Rectangle(lefttopCorner.X, lefttopCorner.Y, rightbottomcorner.X, rightbottomcorner.Y);
                                        text = ocr.GetTextFromImage(bitmap.Image as Bitmap, rect);
                                        ocrTemp.Add(itemdata.Name, text);
                                    }
                                    
                                }
                            }
                        }
                    }

                    CreateXML(item, ocrTemp);
                }
            }



Thanks in advance.

Thanks and Regards
Akshara.

Edited by moderator Friday, July 14, 2017 4:52:46 PM(UTC)  | Reason: Not specified

Paul Rayman  
#2 Posted : Friday, July 14, 2017 4:51:50 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Since I can't reproduce it could you please create a sample app that reproduces your problem? Thanks.
Do not forget to attach language files and pdf documents
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.