PDF Text search C#
-
I have requirement to read a pdf file and search for a text. I should display in which page that text exist and the number of occurances. I can read the pdf to text but i need to know the page number. Thanks
-
Answer:
You can use http://bitmiracle.com/pdf-library/ for this (I work for Bit Miracle). Docotic.Pdf comes with commercial and free licenses. Here is a sample for how to search text in PDF: PdfDocument doc = new PdfDocument("file.pdf"); string textToSearch = "some text"; for (int i = 0; i < doc.Pages.Count; i++) { string pageText = doc.Pages[i].GetText(); int count = 0; int lastStartIndex = pageText.IndexOf(textToSearch, 0, StringComparison.CurrentCultureIgnoreCase); while (lastStartIndex != -1) { count++; lastStartIndex = pageText.IndexOf(textToSearch, lastStartIndex + 1, StringComparison.CurrentCultureIgnoreCase); } if (count != 0) Console.WriteLine("Page {0}: '{1}' found {2} times", i, textToSearch, count); } You may want to remove third argument for IndexOf method if you want to perform case-sensitive search.
dps123 at Stack Overflow Visit the source
Other answers
Have you checked itextsharp out? http://itextsharp.sourceforge.net/ EDIT: To elaborate, in the TOC, i saw a section on: 15.3.3: Extracting text with PdfReaderContentParser and PdfTextExtractor And under PdfReaderContentParser: http://api.itextpdf.com/com/itextpdf/text/pdf/parser/PdfReaderContentParser.html there is an option to process the pdf content per page. So it seems to be a round about way, but you can iterate through each page, searching the content for the word that you want and then return the page that you found it under.
Joe
Related Q & A:
- How do I convert a PDF file to PDF/A in Delphi?Best solution by softwarerecs.stackexchange.com
- How to Set Specific Site Collection as SharePoint Search Scope using C#?Best solution by SharePoint
- How to weight in full-text search?Best solution by Stack Overflow
- How to color a part of the text c#?Best solution by Stack Overflow
- How to search for a particular string in a text file using java?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.