1. 程式人生 > >win7 python pdf2image入坑經歷

win7 python pdf2image入坑經歷

enume spa opp style pop path log 並且 blog

Python開發菜鳥入坑

項目要求pdf轉成圖片,網上較多的方案對於windows極其不友好,wand,Pythonmagick(win下載地址:www.lfd.uci.edu/~gohlke/pythonlibs/#pythonmagick),imagemagick(win下載地址:www.imagemagick.org/download/),poppler(win下載地址://blog.alivate.com.au/poppler-windows/)等多個方案嘗試後仍然不行,並且第三方的模塊安裝導致了window系統爆炸,無法正常使用(大概是window不太適合編程),於是決定去看pdf2image庫源碼(https://github.com/Belval/pdf2image),現分享pdf2image小demo,親測有用。

from pdf2image import convert_from_path
import os

def demo():
    try:
        images = convert_from_path(filename)
        for idx, img in enumerate(images):
            path={}.jpg.format(idx)
            img.save(os.path.join(./img/,path,JPEG,quality=100))
    except Exception as e:
        
print(e) if __name__==__main__: demo()

win7 python pdf2image入坑經歷