import pdfplumber
def extract_content(pdf_path):
with pdfplumber.open('E:\\pythonProject1\\mii.pdf') as pdf_file:
content = ''
for i in range(len(pdf_file.pages)):
page_text = pdf_file.pages[i]
page_content = page_text.extract_text()
if page_content:
content = content + page_content + "\n"
with open("mii.txt", "w", encoding="utf-8") as file:
file.write(content)
file.close()
if __name__ == '__main__':
pdf_file = "../pythonProject1/mii.pdf"
extract_content(pdf_file)
将open和pdf_file里的路径换掉即可