在asp.net C#PDF内容搜索 [英] PDF content search in asp.net c#

查看:551
本文介绍了在asp.net C#PDF内容搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我的要求是使用PDF格式的内容,搜索的PDF文件。

Actually my requirement is to search pdf files using the pdf content.

我有很多的PDF文件的文件夹。
我想开发一个ASP.net应用程序,使用户能够
用他们的文本框里面提供的内容搜索PDF。

I have a folder with a lot of PDF files. I would like to develop an ASP.net application that enables the user to search pdf using the content provided by them inside a textbox.

如何执行这项任务?
感谢ü提前。

how to perform this task? thank u in advance.

推荐答案

你的任务可以分成以下子任务:

Your task may be split into following subtasks:


  1. 制定索引器将索引的所有PDF文件的

  2. 发展的code查找相关PDF每当执行搜索(使用索引,当然)

  3. 如果什么也没有找到开发功能,将打开相关的PDF或显示警告

要建立索引你可以使用如Apache Lucene的或 Lucene.Net 一些集成的解决方案或每个PDF转换成文本和文本自己建立索引。

To build index you may use some integrated solution like Apache Lucene or Lucene.Net or convert each PDF into text and build index from the text yourselves.

您可以尝试为索引部分 Docotic.Pdf库(声明:我对位工作的奇迹)。

You may try Docotic.Pdf library for the indexer part (disclaimer: I work for Bit Miracle).

该库可用于提取文本(带或不带格式化)。所提取的文本可以用于创建索引。

The library could be used to extract text (with or without formatting). The extracted text can be used to create an index.

库还可以检索的字而与他们的边界矩形从PDF文件的。如果您需要了解在文件中的文本的确切位置,这可能是有用的。

The library can also retrieve a collection of words with their bounding rectangles from PDFs. This might be useful if you need to know exact position of a text in a file.

如果您不希望建立索引,那么你仍然可以使用Docotic.Pdf执行使用code类似如下的搜索:

If you don't want to build an index then you still can use Docotic.Pdf to perform searches using a code like the following:

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);
}

这篇关于在asp.net C#PDF内容搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆