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