我想使用imagemagick魔杖包将PDF文件的所有页面转换为单个图像文件。我虽然具有下列麻烦(见下面的注释其中的突出问题)imagemagick魔杖保存pdf页面作为图像
import tempfile
from wand.image import Image
with file('my_pdf_with_5_pages.png') as f:
image = Image(file=f, format='png')
save_using_filename(image)
save_using_file(image)
def save_using_filename(image):
with tempfile.NamedTemporaryFile() as temp:
# this saves all pages, but a file for each page (so 3 files)
image.save(filename=temp.name)
def save_using_file(image):
with tempfile.NamedTemporaryFile() as temp:
# this only saves the first page as an image
image.save(file=temp)
我的最终目标是要能够指定哪些网页将被转换成一个连续的图像。这是从命令行有点可能
convert -append input.pdf[0-4]
但我想与python一起工作。
我看我们可以通过这样得到片:
[x for x in w.sequence[0:1]] # get page 1 and 2
现在它的如何将这些网页连接起来的问题。
谢谢@Steve。运行代码一个小时左右后,我注意到内存泄漏。你可以把你的代码放在一个循环中,并在发生内存泄漏时回报。会很高兴知道:) – rikAtee