首页 > 解决方案 > 将pdf转换为图像但放大后

问题描述

链接显示如何pdf将 s 转换为图像。有没有办法pdf在转换为图像之前缩放我的 s?在我的项目中,我将pdfs 转换为pngs,然后使用Python-tesseract库来提取文本。我注意到如果我缩放pdfs 然后将部分保存为pngs 那么 OCR 会提供更好的结果。那么有没有办法在转换为png之前缩放pdf?

标签: imagepdfocrpython-tesseractpoppler

解决方案


我认为提高图像的质量(分辨率)是比放大 pdf 更好的解决方案。

使用pdf2image你可以很容易地做到这一点:

安装pdf2image:pip install pdf2image

然后,在 python 中,将您的 pdf 转换为高质量图像:

from pdf2image import convert_from_path

pages = convert_from_path('sample.pdf', 400) #400 is the Image quality in DPI (default 200)

pages[0].save("sample.png")

通过使用质量参数,您应该得到您想要的结果


推荐阅读