pymupdf只能提取出文字清晰的pdf。
使用wand的时候有些pdf处理不了,会报图像出错的bug,那些wand处理的不了pdf几乎都是扫描的pdf。
判断扫描的pdf可能是文字不清晰,也可能是格式问题。不容易处理。
所以,想要把pdf转化为图片,然后再用ocr识别图片中的文字。
下面代码,用wand把pdf转化为图片,不过pdf为扫描文件的时候会报错CorruptImageError: unable to read image data
from __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')
无无法师
随时随地看视频慕课网APP