pymupdf只能提取出文字清晰的pdf。使用wand的時候有些pdf處理不了,會報圖像出錯的bug,那些wand處理的不了pdf幾乎都是掃描的pdf。判斷掃描的pdf可能是文字不清晰,也可能是格式問題。不容易處理。所以,想要把pdf轉(zhuǎn)化為圖片,然后再用ocr識別圖片中的文字。下面代碼,用wand把pdf轉(zhuǎn)化為圖片,不過pdf為掃描文件的時候會報錯CorruptImageError: unable to read image datafrom?__future__?import?print_function
from?wand.image?import?Image
?
filePath="C:/Users/wt271/Downloads/康熙教子庭訓(xùn)格言.pdf"
with?Image(filename=filePath)?as?img:
????print('pages?=?',?len(img.sequence))
?
????with?img.convert('png')?as?converted:
????????converted.save(filename='imagetest/page.png')
掃描的pdf文件要怎么能轉(zhuǎn)化為圖片?(用pyton)
無無法師
2018-07-09 19:47:06