image - 将pdf转换为图像但放大后
问题描述
此链接显示如何pdf
将 s 转换为图像。有没有办法pdf
在转换为图像之前缩放我的 s?在我的项目中,我将pdf
s 转换为png
s,然后使用Python-tesseract
库来提取文本。我注意到如果我缩放pdf
s 然后将部分保存为png
s 那么 OCR 会提供更好的结果。那么有没有办法在转换为png之前缩放pdf?
解决方案
我认为提高图像的质量(分辨率)是比放大 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")
通过使用质量参数,您应该得到您想要的结果
推荐阅读
- discord.js - 使用 toLowercase 并包含用于响应消息的数组
- javascript - 在 html 选择中获取当前选定的选项 onBlur
- corda - Corda 排水管在无法启动的节点上流动
- c++ - Crypto++ 是否支持 PKCS#7 填充?
- react-native - 如何在同一屏幕中读取获取响应?
- datepicker - 如何使用选项卡打开日期选择器?
- c# - C# - 创建文件,然后将其作为变量对象
- angular - 如何在 Angular Web 应用程序中使用外部 js 文件功能
- c# - 使用 linq 时返回匿名类型结果
- php - 我在“Volley.newRequestQueue”中做错了什么?