Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
OCR SCAN PART PDF DOCUMENT AND WRITE VALUE IN TEXTBOX C#

Some help?   Some recommendation?   I try this but this is for all page 


What I have tried:

private void Button1_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "PDF Files|*.pdf", ValidateNames = true })

            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(ofd.FileName);
                        StringBuilder sb = new StringBuilder();
                       // for (int i =1; i <= reader.NumberOfPages; i++)
                        for (int i = 1; i <= reader.NumberOfPages; i++)

                        {

                                sb.Append(PdfTextExtractor.GetTextFromPage(reader,i));

                        }
                        textBox1.Text = sb.ToString();
                        reader.Close();

                    }

                    catch (Exception ex)

                    {
                        MessageBox.Show(ex.Message,"Message",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    }
                }
            }
        }
Posted
Comments
lmoelleb 2-Jul-19 6:47am    
Start by being specific in your question. What do you want instead of all pages? A single page? A section of a page - if so, how is that section specified? If it is a single page and you do not know how to adjust this example, then I recommend you follow basic C# tutorials so you understand each line in this simple example - if you understand what each line is doing it is trivial to change it to a single page.
Goran Bibic 2-Jul-19 11:03am    
Just first page
lmoelleb 2-Jul-19 11:45am    
If you can't see where the code loops over the pages and process them one by one, then you need to go back to the c# tutorials - and run it through th debugger line by line. Copying code samples from various sources is fine, but always examine the code and learn how it works.
Goran Bibic 3-Jul-19 7:05am    
Code work, but for complete page. Need help for exmple rectangle ona page on specific location to scan values an put into textbox. Understand?
lmoelleb 3-Jul-19 7:09am    
I recommend updating the question to be specific, don't just write comments here - why should people read that? Change the question to ask how to get text inside a rectangle in a PDF, and remove all the unimportant things like updating textbox as you clearly already know how to do that (your original code did it). The more specific you are, the more likely someone with the required knowledge can reply (or even more likely: you can google it).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900