简体   繁体   English

阅读PDF的程序

[英]Program to read PDFs

The program that I'm doing needs to get the text that is written on a PDF and then put the information on a spreadsheet, I also need to be able to just put the PDF on a folder and the run the code instead of putting the name of the PDF on the code.我正在做的程序需要获取写在 PDF 上的文本,然后将信息放在电子表格中,我还需要能够将 PDF 放在文件夹中并运行代码而不是将代码上 PDF 的名称。

This method will use an external module called PyPDF2 to convert PDF to text.此方法将使用名为 PyPDF2 的外部模块将 PDF 转换为文本。 This PyPDF2 package can allow you to convert, split, merge, and crop PDFs.这个 PyPDF2 package 可以让你转换、拆分、合并和裁剪 PDF。

import PyPDF2
pdfFileObj = open('example.pdf', 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
print(pdfReader.numPages)
pageObj = pdfReader.getPage(0)
print(pageObj.extractText())
pdfFileObj.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM