是否有任何功能可以从pdf中提取具有特定标题的文本

Is there any function to extract the text which has a specific heading from pdf

我的 pdf 文档中有多个段落。每个段落都有一个唯一的标题。如何从我要查找的特定标题下的 pdf 中提取文本

您可以为此使用 PyPDF2 python 库,示例片段:

# importing required modules
import PyPDF2

# creating a pdf file object
pdfFileObj = open('example.pdf', 'rb')

# creating a pdf reader object
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)

# printing number of pages in pdf file
print(pdfReader.numPages)

# creating a page object
pageObj = pdfReader.getPage(0)

# extracting text from page
print(pageObj.extractText())

# closing the pdf file object
pdfFileObj.close()