使用 iTextSharp 在多个 PDF 的元数据中搜索字符串
Search for a string within a multiple PDF`s metadata with iTextSharp
如何在目录中的多个 PDF 文件中搜索特定的 'Author' 名称,并在找到后获取该文件的路径?目前我正在使用 EnumerateFiles
浏览目录,然后循环显示每个 PDF 文件中的所有作者姓名 PDfReader
。我只是不知道现在如何搜索那个特定的作者姓名。
我的代码如下:
path = @"C:\Users\thomas\Desktop\PDFfiles";
var files = Directory.EnumerateFiles(path, "*.pdf", SearchOption.AllDirectories);
foreach (string currentFile in files)
{
PdfReader reader = new PdfReader(currentFile);
string authorName = reader.Info["Author"];
listBox1.Items.Add("Author is: " + authorName);
}
我在 ListBox
中获得了作者姓名列表,但如何在所有 PDF 文件中搜索特定姓名?
谢谢
您可能需要使用新列表来保存您选择的作者的结果,例如:newList = listBox1.Items.Where(x => x.Text == authorName);
如何在目录中的多个 PDF 文件中搜索特定的 'Author' 名称,并在找到后获取该文件的路径?目前我正在使用 EnumerateFiles
浏览目录,然后循环显示每个 PDF 文件中的所有作者姓名 PDfReader
。我只是不知道现在如何搜索那个特定的作者姓名。
我的代码如下:
path = @"C:\Users\thomas\Desktop\PDFfiles";
var files = Directory.EnumerateFiles(path, "*.pdf", SearchOption.AllDirectories);
foreach (string currentFile in files)
{
PdfReader reader = new PdfReader(currentFile);
string authorName = reader.Info["Author"];
listBox1.Items.Add("Author is: " + authorName);
}
我在 ListBox
中获得了作者姓名列表,但如何在所有 PDF 文件中搜索特定姓名?
谢谢
您可能需要使用新列表来保存您选择的作者的结果,例如:newList = listBox1.Items.Where(x => x.Text == authorName);