我正在尝试将PDF转换为jpg文件。如果我转换一个大的pdf文件(~80页),Wand只转换前22页。
with Img(filename=file, resolution=300) as pic:
library.MagickResetIterator(pic.wand)
pic.scene = 1 # Start cpt of filename at 1 instead of 0
pic.compression_quality = 100
pic.background_color = Color("white")
pic.alpha_channel = 'remove'
pic.save(filename=(self.output_dir + '/result.jpg'))我不明白为什么,任何帮助都是最好的
谢谢
发布于 2021-03-09 20:32:10
我倾向于认为这与这个操作的工作方式有关。当您打开.pdf文件时,它将objects保存在内存中,这受系统所允许的限制。这意味着您的内存不允许超过22页。加载80个pdf页面会占用巨大的内存空间,而您的解决方案不适用于此类任务。
我会推荐这样的东西( credit)
使用pdf2image
pip install pdf2image然后使用它从pdf中获取图像。
from pdf2image import convert_from_path
pages = convert_from_path('pdf_file', 500)
for page in pages:
page.save('out.png', 'png')https://stackoverflow.com/questions/66544266
复制相似问题