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

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
Akshara  
#1 Posted : Tuesday, February 7, 2017 4:58:25 AM(UTC)
Quote
Akshara

Rank: Member

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

1) I am not able to get coordinates of selected region in PDF using Pdfium pdf viewer
2) I am not able to extract data from respective selected coordinate using "GetBoundedText(float left, float top, float right, float bottom)" function
3) I am no able to extract data from selected region in image by passing coordinates to function "GetTextFromImage(filepath, rect.Location.X,rect.Location.Y,rect.Size.Width,rect.Size.Height)".



above are my issues please provide me with solution.

Paul Rayman  
#2 Posted : Tuesday, February 7, 2017 4:40:01 PM(UTC)
Quote
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)
Originally Posted by: Akshara Go to Quoted Post
1) I am not able to get coordinates of selected region in PDF using Pdfium pdf viewer

What exactly you mean when you say "selected region"?
Quote:

2) I am not able to extract data from respective selected coordinate using "GetBoundedText(float left, float top, float right, float bottom)" function

Please let me see your code.
Quote:

3) I am no able to extract data from selected region in image by passing coordinates to function "GetTextFromImage(filepath, rect.Location.X,rect.Location.Y,rect.Size.Width,rect.Size.Height)".

Pdfium has now any methods named "GetTextFromImage"


Akshara  
#3 Posted : Tuesday, February 7, 2017 10:50:09 PM(UTC)
Quote
Akshara

Rank: Member

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

Quote 1:
Selected region means Rectangle selected by using MouseDown,MouseMove,MoveUp and Paint events of pdfViewer to get the coordinates.
I have tried to get coordinates by using windows canvas method, but I am not able to get the exact coordinates of Selected rectangle considering the PDF document.
Can you please provide me code to draw Coordinates of rectangle selected by us on PDF document in PDFViewer.

Quote 2:
The output of bellow code is not the same region data of which I have given the coordinates,I am getting data which is not selected. I am not able to get the exact data from the rectangle drawn over PDF.
Code is bellow:

Code:

 foreach (var itemdata in pdflist)
            {
                Ocr ocr = new Ocr();
                InitWebApp();
                using (var doc = PdfDocument.Load(itemdata))
                {
                    using (var page = doc.Pages[0])
                    {
                        templateId = Convert.ToInt32(cmbSelTemplate.SelectedValue);
                        List<Ocr> tempMetadata = mapperController.GetOcrMetadata(templateId);//templateMetadata gets the list of coordinates i.e. left,top,right,bottom
                        //delcare a dict with key and value string key-name
                        Dictionary<string, string> ocrTemp = new Dictionary<string, string>();
                        foreach (var item in tempMetadata)
                        {
                            var textInfo = page.Text.GetBoundedText(Convert.ToInt32(item.Left ), Convert.ToInt32(item.Top), Convert.ToInt32((item.Right - item.Left) ), Convert.ToInt32((item.Bottom - item.Top) ));
                            ocrTemp.Add(item.Name, textInfo);
                        }
                        CreateXML(itemdata, ocrTemp);
                    }
                }
            }




Quote 3:
The output of bellow code is not in appropriate Human readable language,it is combination of characters,numbers and symbols.I am not able to get the exact data from the rectangle drawn over PDF.
Code is bellow:
Code:

 OcrApi.LicenseKey = ConfigurationManager.AppSettings["LicenseKeyOcr"];
            using (var api = OcrApi.Create())
            {
                templateId = Convert.ToInt32(cmbSelTemplate.SelectedValue);
                List<Ocr> tempMetadata = mapperController.GetOcrMetadata(templateId);
                foreach (var item in tempMetadata)
                {
                    api.Init(Languages.English);
                   
                    var rect = new Rectangle(Convert.ToInt32(item.Left), Convert.ToInt32(item.Top), Convert.ToInt32((item.Right - item.Left)), Convert.ToInt32((item.Bottom - item.Top)));
                    
                    string plainText = api.GetTextFromImage(filepath, rect.Location.X,rect.Location.Y,rect.Size.Width,rect.Size.Height);
                   ocrTemp.Add(item.Name, plainText);
                }
                return ocrTemp;
            }

Edited by moderator Wednesday, February 8, 2017 9:48:12 PM(UTC)  | Reason: Not specified

Paul Rayman  
#4 Posted : Wednesday, February 8, 2017 10:08:19 PM(UTC)
Quote
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)
Quote 1:
Quote:

Can you please provide me code to draw Coordinates of rectangle selected by us on PDF document in PDFViewer.

Please look at this topic
http://forum.patagames.com/posts/t272-Does-pdf-viewer-have-the-take-snapshot-functionality-as-Acrobat

Quote 2:
The GetBoundedText method takes the rectangle in PDF standard user space coordinates.
So you should convert your rectangle to page coordinate system.
Please find the ClientToPage method here: https://pdfium.patagames...c9-ed83-a4d9de8a35f8.htm



Quote 3:
Quote:

The output of bellow code is not in appropriate Human readable language,it is combination of characters,numbers and symbols.

https://github.com/tesseract-ocr/tesseract/wiki/ImproveQuality

Edited by user Wednesday, February 8, 2017 10:52:27 PM(UTC)  | Reason: Not specified

Akshara  
#5 Posted : Friday, February 10, 2017 3:40:20 AM(UTC)
Quote
Akshara

Rank: Member

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

Thanks Paul for the help, it worked.

But I have two more queries

1.How to render Annotations on PDF and to save the PDF with that annotations?
2.I am not able to convert multiple images to a single PDF. Bellow is written code for it-
Code:

 public void PdfCreationFromImage(List<string> imagePathList)
        {

            OcrApi.LicenseKey = ConfigurationManager.AppSettings["LicenseKeyOcr"];
            using (var api = OcrApi.Create())
            {
                api.Init(Languages.English);
                //Create the renderer to PDF file output. The extension will be added automatically
                using (var renderer = OcrPdfRenderer.Create("Template_pdf_file", @"~\DigiSync\DigiSync.Manager\TemplateOutput\"))
                {
                    renderer.BeginDocument("Title");
//imagePathList is a list of image path which i want to combine to form a single PDF
                    foreach (var item in imagePathList)
                    {
                        api.ProcessPages(item, null, 0, renderer);
                    }
                    renderer.EndDocument();
                }
            }

        }


i have tried the following link provided by you to convert image to PDF but didn't work.
https://tesseract.patagames.com/

Edited by moderator Thursday, February 16, 2017 4:46:09 PM(UTC)  | Reason: Not specified

Paul Rayman  
#6 Posted : Thursday, February 16, 2017 5:00:21 PM(UTC)
Quote
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)
If data files are actually placed in tessdata folder, then the last parameter of renderer.Create method must be ends with "tessdata\".

Code:

using (var renderer = OcrPdfRenderer.Create("Template_pdf_file", @"~\DigiSync\DigiSync.Manager\TemplateOutput\tessdata\"))

Quick Reply Show Quick Reply
Users browsing this topic
Guest (3)
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.