Python WAND WandRuntimeError
Python WAND WandRuntimeError
我有以下 python 代码将 PDF 转换为 JPG。
with Img(filename=pdfName, resolution=300) as pic:
pic.compression_quality = self.compressionQuality
pic.background_color = Color("white")
pic.alpha_channel = 'remove'
pic.save(filename=output)
我的问题是,对于较大的 PDF 文件 (10mb),出现以下错误:
File "/home/nathan/PycharmProjects/oc_for_maarch/worker.py", line 44, in <module>
launch(args)
File "/home/nathan/PycharmProjects/oc_for_maarch/src/main.py", line 105, in launch
q = process(args, path + file, Log, Separator, Config, Image, Ocr, Locale, WebService, q)
File "/home/nathan/PycharmProjects/oc_for_maarch/src/process/OCForMaarch.py", line 48, in process
Image.pdf_to_jpg(file + '[0]')
File "/home/nathan/PycharmProjects/oc_for_maarch/src/classes/Images.py", line 36, in pdf_to_jpg
self.save_img_with_wand(pdfName, self.jpgName)
File "/home/nathan/PycharmProjects/oc_for_maarch/src/classes/Images.py", line 46, in save_img_with_wand
with Img(filename=pdfName, resolution=300) as pic:
File "/home/nathan/Documents/OpenCV/lib/python3.7/site-packages/wand/image.py", line 6406, in __init__
self.read(filename=filename, resolution=resolution)
File "/home/nathan/Documents/OpenCV/lib/python3.7/site-packages/wand/image.py", line 6799, in read
raise WandRuntimeError(msg)
wand.exceptions.WandRuntimeError: MagickReadImage returns false, but did raise ImageMagick exception. This can occurs when a delegate is missing, or returns EXIT_SUCCESS without generating a raster.
我在 Internet 上查了一下,据我所知,问题与 ghostscript
有关,但已安装
我在 Debian 10 和 Ubuntu 19.04 使用 Python 3.7
时遇到问题
编辑:如果我将分辨率设置为 100 而不是 300,我就没有问题
当您以高密度光栅化时,您将从您的 PDF 生成一个可能非常大尺寸的图像。所以听起来您可能 运行 内存不足。如果是这样,那么您需要编辑 ImageMagick policy.xml 文件以允许更多的 ram 或映射 space。请参阅 https://imagemagick.org/script/resources.php 中的 policy.xml。它控制您的资源,您可以使用命令行命令查看这些资源:
convert -list resource
我有以下 python 代码将 PDF 转换为 JPG。
with Img(filename=pdfName, resolution=300) as pic:
pic.compression_quality = self.compressionQuality
pic.background_color = Color("white")
pic.alpha_channel = 'remove'
pic.save(filename=output)
我的问题是,对于较大的 PDF 文件 (10mb),出现以下错误:
File "/home/nathan/PycharmProjects/oc_for_maarch/worker.py", line 44, in <module>
launch(args)
File "/home/nathan/PycharmProjects/oc_for_maarch/src/main.py", line 105, in launch
q = process(args, path + file, Log, Separator, Config, Image, Ocr, Locale, WebService, q)
File "/home/nathan/PycharmProjects/oc_for_maarch/src/process/OCForMaarch.py", line 48, in process
Image.pdf_to_jpg(file + '[0]')
File "/home/nathan/PycharmProjects/oc_for_maarch/src/classes/Images.py", line 36, in pdf_to_jpg
self.save_img_with_wand(pdfName, self.jpgName)
File "/home/nathan/PycharmProjects/oc_for_maarch/src/classes/Images.py", line 46, in save_img_with_wand
with Img(filename=pdfName, resolution=300) as pic:
File "/home/nathan/Documents/OpenCV/lib/python3.7/site-packages/wand/image.py", line 6406, in __init__
self.read(filename=filename, resolution=resolution)
File "/home/nathan/Documents/OpenCV/lib/python3.7/site-packages/wand/image.py", line 6799, in read
raise WandRuntimeError(msg)
wand.exceptions.WandRuntimeError: MagickReadImage returns false, but did raise ImageMagick exception. This can occurs when a delegate is missing, or returns EXIT_SUCCESS without generating a raster.
我在 Internet 上查了一下,据我所知,问题与 ghostscript
有关,但已安装
我在 Debian 10 和 Ubuntu 19.04 使用 Python 3.7
时遇到问题编辑:如果我将分辨率设置为 100 而不是 300,我就没有问题
当您以高密度光栅化时,您将从您的 PDF 生成一个可能非常大尺寸的图像。所以听起来您可能 运行 内存不足。如果是这样,那么您需要编辑 ImageMagick policy.xml 文件以允许更多的 ram 或映射 space。请参阅 https://imagemagick.org/script/resources.php 中的 policy.xml。它控制您的资源,您可以使用命令行命令查看这些资源:
convert -list resource