嗨,我正在尝试将多页 pdf 转换为单图像。
从我的代码中我只能生成多个(列表)图像。
我们如何从 pdf 创建多页单图像。
下面是我的代码
**
import requests
from pdf2image import convert_from_path
url = 'https://education.github.com/git-cheat-sheet-education.pdf'
r = requests.get(url, stream=True)
with open('F:/New folder/metadata.pdf', 'wb') as f:
f.write(r.content)
pages = convert_from_path('F:/New folder/metadata.pdf', 500,poppler_path=r'C:\poppler-0.68.0\bin')
for count, page in enumerate(pages):
page.save(f'F:/New folder/out{count}.jpg', 'JPEG')
**
对上述代码请求任何建议/修改吗?
谢谢你
是的,您无法制作多页 JPEG 或 PNG。多页图像有一种文件格式:TIFF。创建方法如下:
from pdf2image import convert_from_path
from PIL import Image
# Convert the PDF to a list of images
images = convert_from_path('F:/New folder/metadata.pdf')
# Save the images as a multi-page TIFF
images[0].save('output.tiff', 'TIFF', save_all=True, append_images=images[1:])