0

我需要使用 C# 在 Visual Studio 2010 中创建一个 winform,它在目录中搜索 pdf 文件,然后在 pdf 中搜索某些文本。例如,用户可以在 winform 中输入“John Smith”。该程序需要在给定目录中的所有 pdf 中搜索文本“John Smith”。我目前没有 Adob​​e Acrobat,可能无法购买它或任何非免费插件。我被告知要查看 Apache Solr 和 Ghostscript,但看不到如何在 winform 中使用它们。我已经搜索了很多并看到了很多建议,但是找不到任何关于如何设置 winform 来搜索 pdf 的简单示例或教程。有人可以为我提供一些关于如何在 winform 中搜索 pdf 的示例代码吗?

4

1 回答 1

3

要在 PDF 中搜索特定文本,您可以使用位于http://sourceforge.net/projects/itextsharp/的 ITextSharp 库

这是一个简单的例子

var reader = new PdfReader(pdfPath); 
StringWriter output = new StringWriter();  

for (int i = 1; i <= reader.NumberOfPages; i++) 
    output.WriteLine(PdfTextExtractor.GetTextFromPage(reader, i, new SimpleTextExtractionStrategy()));

//now you can search for the text from outPut.ToString();
于 2012-07-30T13:07:11.137 回答