pdf2image

https://github.com/Belval/pdf2image

 

 

 


from pdf2image import convert_from_path, convert_from_bytes
import os, time, sys

def pdf2jpg():
    try:
        image = convert_from_path(sys.argv[1])[0]
        path = '{}.jpg'.format(time.time())
        image.save(os.path.join('./img/', path), 'JPEG',quality=100)
        if os.path.exists(sys.argv[1]):
            os.remove(sys.argv[1])
        print(path)
    except Exception as e:
        print(e)

if __name__ == '__main__':
    pdf2jpg()






 

你可能感兴趣的:(python高级)