读取一个本地pdf文件,输出字符串
# -*- coding: UTF-8 -*from urllib import urlopenfrom pdfminer.pdfinterp import PDFResourceManager, process_pdffrom pdfminer.converter import TextConverterfrom pdfminer.layout import LAParamsfrom io import StringIOfrom io import opendef readPDF(pdfFile): rsrcmgr = PDFResourceManager() retstr = StringIO() laparams = LAParams() device = TextConverter(rsrcmgr, retstr, laparams=laparams) process_pdf(rsrcmgr, device, pdfFile) device.close() content = retstr.getvalue() retstr.close() return contentpdfFile = open(u"/home/mypdf.pdf",”rd”) #本地
print(pdfFile)outputString = readPDF(pdfFile)print(outputString)pdfFile.close()