将单页 PDF 转换为图像

发布于 2025-01-16 18:54:45 字数 286 浏览 4 评论 0原文

我正在尝试使用以下代码将 pdf 转换为图像

from pdf2image import convert_from_path

pages = convert_from_path('Sample.pdf', 50, poppler_path=r'C:\Program Files\poppler-20.11.0\bin')
pages[0].save('OutImage.jpg', 'JPEG')

该代码正在运行,但我正在尝试控制输出图像以使其大小为 1389 x 1965 请你指导我好吗?

I am trying to convert pdf to an image using the following code

from pdf2image import convert_from_path

pages = convert_from_path('Sample.pdf', 50, poppler_path=r'C:\Program Files\poppler-20.11.0\bin')
pages[0].save('OutImage.jpg', 'JPEG')

The code is working but I am trying to control the output image to make its size 1389 x 1965
Can you guide me, please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素手挽清风 2025-01-23 18:54:45

找到 convert_from_path大小参数代码>函数

尺寸->生成图像的大小,使用 Pillow(宽度、高度)标准

使用示例:

from pdf2image import convert_from_path

pages = convert_from_path("eng.pdf", 50, size=(1389, 1965))
pages[0].save("OutImage.jpg", "JPEG")
$ file OutImage.jpg
OutImage.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 1389x1965, components 3

Found size parameter of convert_from_path function

size -> Size of the resulting image(s), uses the Pillow (width, height) standard

Example of using it:

from pdf2image import convert_from_path

pages = convert_from_path("eng.pdf", 50, size=(1389, 1965))
pages[0].save("OutImage.jpg", "JPEG")
$ file OutImage.jpg
OutImage.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 1389x1965, components 3

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文