read pdf file horizontally with pdfminer

别来无恙 提交于 2019-12-06 02:35:24

I have found a working solution with pdftotext:

import tempfile, subprocess

def pdf_to_string(file_object):
    pdfData = file_object.read()
    tf = tempfile.NamedTemporaryFile()
    tf.write(pdfData)
    tf.seek(0)
    outputTf = tempfile.NamedTemporaryFile()

    if (len(pdfData) > 0) :
        out, err = subprocess.Popen(["pdftotext", "-layout", tf.name, outputTf.name ]).communicate()
        return outputTf.read()
    else :
        return None

pdf_file="files/2014_1.pdf"
file_object = file(pdf_file, 'rb')
print pdf_to_string(file_object)

This produces the right output, person names then positions :).

Solved!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!