python处理pdf文件

  • emded 标签

  • pre标签

  • 爬虫爬取pdf文档:

    1. 下载 pdfminer3k
    2. 安装 python setup.py install
    3. 代码
from urllib.request import urlopen
from pdfminer.pdfinterp import PDFResourceManager, process_pdf
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from io import StringIO
from io import open

def 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 content
pdfFile = urlopen('http://www.cncbinternational.com/_document/about-us/investor-relations/regulatory-disclosure/tc/2014-12-31/Balance-Sheet-Recon-and-Extract-of-Transition-Disclosures-Template_31-December-2014.pdf')
outputString = readPDF(pdfFile)
print(outputString)
pdfFile.close()

4.这个模块读出来的pdf不太标准,要研究下源码

你可能感兴趣的:(python处理pdf文件)