开发者

How-to extract text from a pdf doc within a specific rectangular region? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 5 years ago.

Improve this question

I have to extract text from a pdf doc within a specific rectangular region. The work-flow is as following.开发者_运维问答 First of all pdf is converted to an jpg image. Then user draws selection rectangle on top of the picture. Then I somehow need to extract all text from pdf doc within that selection region. Any suggestions what freeware pdf libs accessible from C# to use?


this code will perfectly extract pdf data on the basis of rectangular coordinates using itextsharp

    List<string> linestringlist = new List<string>();
    PdfReader reader = new PdfReader(pdfFilename);
    iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(coordinate1, coordinate2, coordinate3, coordinate4);
    RenderFilter[] renderFilter = new RenderFilter[1];
    renderFilter[0] = new RegionTextRenderFilter(rect);
    ITextExtractionStrategy textExtractionStrategy = new FilteredTextRenderListener(new LocationTextExtractionStrategy(), renderFilter);
    string text = PdfTextExtractor.GetTextFromPage(reader, 1, textExtractionStrategy);


I agree, OCR is not the approach to use here. You need a PDF library that can extract the text along with the bounding box coordinates.

QuickPDF is a commercial library (www.quickpdf.com) that can extract the required information for a very reasonable price of $249. http://www.quickpdflibrary.com/help/quickpdf/DAExtractPageText.php is the function you are looking for. This will extract the text for the whole page and then you would need to use simple Point and/or Rectangle functions to limit the text to your selected rectangle.

I don't believe iText has this capability based on my research.

You should also read How to extract text from a PDF?


I would suggest you once you have rasterized the PDF into a JPEG image to use text recognition (OCR) to extract the text within the selected region. Here's an article about an OCR library for .NET. As far as extracting text from PDF is concerned here's an article illustrating how this be achieved more or less reliably. The problem will be how to recognize the text within the selected rectangle by the user.


(disclaimer - I work for Atalasoft on its PDF products) Atalasoft's PdfReader will do this. It's not freeware, but it works quite well. The code looks like this:

using (PdfTextDocument doc = new PdfTextDocument(pathToFile)) {
    PdfTextPage page = doc.GetPage(pageNumber);
    string text = page.GetTextInBox(yourSelection);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜