我正在尝试将PDF转换为PNG - 这一切都运行正常,但是,即使我相信我已将其禁用,输出图像仍然是透明的:
with Image(filename='sample.pdf', resolution=300) as img:
img.background_color = Color("white")
img.alpha_channel = False
img.save(filename='image.png')
Run Code Online (Sandbox Code Playgroud)
以上产生图像但透明,我也试过以下:
with Image(filename='sample.pdf', resolution=300, background=Color('white')) as img:
img.alpha_channel = False
img.save(filename='image.png')
Run Code Online (Sandbox Code Playgroud)
产生此错误:
Traceback (most recent call last):
File "file_convert.py", line 20, in <module>
with Image(filename='sample.pdf', resolution=300, background=Color('white')) as img:
File "/Users/Frank/.virtualenvs/wand/lib/python2.7/site-packages/wand/image.py", line 1943, in __init__
raise TypeError("blank image parameters can't be used with image "
TypeError: blank image parameters can't be used with image opening parameters
Run Code Online (Sandbox Code Playgroud) 我想将一些多页.tif或.pdf文件转换为单独的.png图像.从命令行(使用ImageMagick)我只是这样做:
convert multi_page.pdf file_out.png
Run Code Online (Sandbox Code Playgroud)
我将所有页面作为单独的图像(file_out-0.png,file_out-1.png,...)
我想在Python中处理这个文件转换,遗憾的是PIL无法读取.pdf文件,所以我想使用PythonMagick.我试过了:
import PythonMagick
im = PythonMagick.Image('multi_page.pdf')
im.write("file_out%d.png")
Run Code Online (Sandbox Code Playgroud)
要不就
im.write("file_out.png")
Run Code Online (Sandbox Code Playgroud)
但我只有1页转换为png.当然,我可以单独加载每个页面并逐个转换它们.但必须有办法一次完成所有这些操作吗?
所以我正在使用 Wand 尝试将 pdf 转换为图像
from wand.image import Image
with Image(filename="test.pdf") as img:
img.save(filename="/temp.jpg")
with Image(filename="test.jpg") as img:
img.resize(200, 150)
img.save(filename="t.jpg")
Run Code Online (Sandbox Code Playgroud)
但出于某种原因,我得到:
Traceback (most recent call last):
File "C:\Users\Rafael\Desktop\k\pdf to image.py", line 3, in <module>
with Image(filename="test.pdf") as img:
File "C:\Python27\lib\site-packages\wand\image.py", line 2534, in __init__
self.read(filename=filename, resolution=resolution)
File "C:\Python27\lib\site-packages\wand\image.py", line 2601, in read
self.raise_exception()
File "C:\Python27\lib\site-packages\wand\resource.py", line 222, in raise_exception
raise e
DelegateError: PDFDelegateFailed `The system cannot find the file specified.
' @ error/pdf.c/ReadPDFImage/798
Run Code Online (Sandbox Code Playgroud)
我可以做些什么还是有另一种方法可以将 pdf 转换为图像?