【发布时间】:2019-01-15 02:52:40
【问题描述】:
我正在尝试运行一个脚本,该脚本将遍历特定文件夹并使用 Wand 创建它在该文件夹中找到的每个 .pdf 文件的 .png 文件。
from wand.image import Image
import os
pdf_dir = r"D:\Program Files\Python\Python36-32\tom's shitty programs\Downloads"
对于 x在 os.listdir(pdf_dir):
if x.endswith(".pdf"):
pdf_path = pdf_dir + '\\' + x
with Image(filename=pdf_path, resolution=300) as pdf:
page_index = 0
height = pdf.height
with Image(width=pdf.width, height=len(pdf.sequence)*height) 为 png:
用于 pdf 中的页面。序列:
png.composite(page, 0, page_index * height)
page_index += 1
png.save(filename=pdf_path[:-3] + "png")
这会返回以下错误:
Traceback(最近一次调用最后一次):
文件“D:\Program Files\Python\Python36-32\tom's shitty programs\venv\lib\site-packages\wand\image.py”,第 1799 行,在 wand 返回 self.resource
文件“D:\Program Files\Python\Python36-32\tom's shitty programs\venv\lib\site-packages\wand\resource.py”,第 151 行,资源引发 DestroyedResourceError(repr(self) + '已经被销毁了')
wand.resource.DestroyedResourceError: 已被销毁
在处理上述异常的过程中,又发生了一个异常:
Traceback(最近一次调用最后一次):
文件“D:/Program Files/Python/Python36-32/tom's shitty programs/wand_test.py”,第 13 行,带有 Image(width=pdf.width, height=len(pdf.sequence)*height)作为png:
文件“D:\Program Files\Python\Python36-32\tom's shitty programs\venv\lib\site-packages\wand\image.py”,第 1817 行,宽度返回库。MagickGetImageWidth(self.wand)
文件“D:\Program Files\Python\Python36-32\tom's shitty programs\venv\lib\site-packages\wand\image.py”,第 1801 行,在 wand raise ClosedImageError(repr(self) + '已经关门了')
wand.image.ClosedImageError: 已经关闭
感谢您的帮助...谢谢
【问题讨论】:
标签: python python-3.x pdf wand