本文介绍了Python:从pdf中提取页面作为jpeg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python代码中,如何有效地将pdf中的某个页面保存为jpeg文件? (使用案例:我有一个python flask web服务器,其中将上传pdf-s,每个页面对应的jpeg-s是商店。)

In python code, how to efficiently save a certain page in a pdf as a jpeg file? (Use case: I've a python flask web server where pdf-s will be uploaded and jpeg-s corresponding to each page is stores.)

已接近,但问题是它没有将整个页面转换为jpeg。

This solution is close, but the problem is that it does not convert the entire page to jpeg.

推荐答案

可以使用pdf2image库。

The pdf2image library can be used.

您只需使用

pip install pdf2image

安装完成后,您可以使用以下代码来获取图像。

Once installed you can use following code to get images.

from pdf2image import convert_from_path
pages = convert_from_path('pdf_file', 500)

以jpeg格式保存页面

Saving pages in jpeg format

for page in pages:
    page.save('out.jpg', 'JPEG')






编辑:Github repo 还提到它使用 pdftoppm 并且它需要其他安装:


the Github repo pdf2image also mentions that it uses pdftoppm and that it requires other installations:

以下是Windows的正确安装:

Here is the proper installation for Windows: http://blog.alivate.com.au/poppler-windows/

这篇关于Python:从pdf中提取页面作为jpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:31