问题描述
我正在尝试使用 PyPDF 在 PDF 中进行搜索,并返回使用 re.search 找到搜索词的页码。但是,当单词中包含连字符时,它不起作用。例如,搜索“abc-123”没有任何返回。我尝试了下面的代码,它适用于搜索“123”或“abc”,但不会返回“abc-123”。以下是我的代码,来自 this thread。
# Open the pdf file
pdfFileObj = open('example.pdf','rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
String = 'abc-123'
# Extract text and do the search
for i in range(0,NumPages):
PageObj = pdfReader.getPage(i)
Text = PageObj.extractText()
if re.search(String,Text):
print("Pattern Found on Page: " + str(i))
pdfFileObj.close()
感谢任何帮助。提前致谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)