我想用pdfminer 和tabula解析一个 PDF 文件
我读了这个 问题并使用了这段代码:
从 pdfminer.pdfparser 导入 PDFParser 从 pdfminer.pdfdocument 导入 PDFDocument
import magic
from pyPdf import PdfFileWriter, PdfFileReader
import tabula
import numpy as np
filename = '/home/parser/test.pdf'
magic.from_file(filename,mime=True)
ifpdf = PdfFileReader(file(filename, "rb"))
pdf_info = ifpdf.getDocumentInfo()
nm = [ 'Info_1', 'Info_2','Info_3','Info_4']
df = tabula.read_pdf(filename,pages="all",lattice="all",pandas_options={'header': None,'names':nm,'encoding':'utf-8'})
df.refenseigne.replace(to_replace=r"(M|C)\r",value="",regex=True,inplace=True)
df.to_csv("test.csv",encoding="utf-8")
当我执行我的代码时,我得到了这个错误
Traceback (most recent call last):
File "parse_pdf.py", line 16, in <module>
df = tabula.read_pdf(filename,pages="all",lattice="all",pandas_options={'header': None,'names':nm,'encoding':'utf-8'})
File "/usr/local/lib/python2.7/dist-packages/tabula/wrapper.py", line 87, in read_pdf
output = subprocess.check_output(args)
File "/usr/lib/python2.7/subprocess.py", line 567, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
奇怪的是,在第 9 行和第 11 行我可以找到该文件,但在第 16 行我有这个错误。
我错了还是表格问题?