Articles in this section
Category / Section

How to extract text from the predefined rectangle in WinForms PDF Viewer?

2 mins read

In WinForms PDF Viewer you can extract text from the given rectangular region on a page by exporting the page to an image, cloning the exported image with the given rectangle, and performing OCR on the cloned image. Refer to the following code snippet.

    

C#

PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../Data/Barcode.pdf");
            using (OCRProcessor processor = new OCRProcessor("../../Tesseract binaries"))
            {
                //Language to process the OCR
                processor.Settings.Language = Languages.English;
                Bitmap image = loadedDocument.ExportAsImage(0);
                //Define the bounds from which the text to be extracted
                Rectangle textBounds = new Rectangle(274, 53, 68, 15);
                //Point to Pixel conversion
                RectangleF rect = new RectangleF(textBounds.X * 1.3333f, textBounds.Y * 1.3333f, textBounds.Width * 1.3333f, textBounds.Height * 1.3333f);
                using (Bitmap clonedImage = image.Clone(rect, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                {
                    string ocrText = processor.PerformOCR(clonedImage, @"../../Tessdata/");                 
                }
                image.Dispose();
            }
 

 

Sample link:

https://www.syncfusion.com/downloads/support/directtrac/general/ze/ExtractTextFromBounds_(2)-259553055

Conclusion

I hope you enjoyed learning about how to extract text from the predefined rectangle from a PDF document. 

You can refer to our  WinForms PDF Viewer’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF Viewer documentation to understand how to present and manipulate data. 

 For current customers, you can check out our WinForms from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms PDF Viewer and other WinForms components.

 If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied