print imagemagick 将输出转换为浏览器
print imagemagick convert output to browser
我有以下代码:
import subprocess
convertargs = ['convert', 'image1.tif', 'img2.tif', 'pdf:-']
print "Content-type: application/pdf\r\n\r\n"
pdf = subprocess.Popen(convertargs, stdout=subprocess.PIPE)
pdf, error = pdf.communicate()
print pdf
应该是带convertargs的,用imagemagick的convert把图片转成pdf。
我知道这行得通,因为当我 运行 在 shell 处执行以下操作时:
./pdf.py > test.pdf
它为我创建了一个带有正确图像的简洁的小 PDF。但是,当我转到 www.myhost.com/pdf.py 时,它不起作用。我不知道为什么。
这是我的 apache 错误日志中的内容:
Traceback (most recent call last):: /Library/WebServer/Documents/pdf.py
File "/Library/WebServer/Documents/pdf.py", line 59, in <module>: /Library/WebServer/Documents/pdf.py
pdf = subprocess.Popen(convertargs, stdout=subprocess.PIPE): /Library/WebServer/Documents/pdf.py
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__: /Library/WebServer/Documents/pdf.py
errread, errwrite): /Library/WebServer/Documents/pdf.py
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child: /Library/WebServer/Documents/pdf.py
raise child_exception: /Library/WebServer/Documents/pdf.py
OSError: [Errno 2] No such file or directory: /Library/WebServer/Documents/pdf.py
subprocess.Popen
找不到 convert
,可能是因为网络服务器使用了不同的 $PATH。尝试将完整路径提供给 convert
而不是 convert
.
我有以下代码:
import subprocess
convertargs = ['convert', 'image1.tif', 'img2.tif', 'pdf:-']
print "Content-type: application/pdf\r\n\r\n"
pdf = subprocess.Popen(convertargs, stdout=subprocess.PIPE)
pdf, error = pdf.communicate()
print pdf
应该是带convertargs的,用imagemagick的convert把图片转成pdf。
我知道这行得通,因为当我 运行 在 shell 处执行以下操作时:
./pdf.py > test.pdf
它为我创建了一个带有正确图像的简洁的小 PDF。但是,当我转到 www.myhost.com/pdf.py 时,它不起作用。我不知道为什么。 这是我的 apache 错误日志中的内容:
Traceback (most recent call last):: /Library/WebServer/Documents/pdf.py
File "/Library/WebServer/Documents/pdf.py", line 59, in <module>: /Library/WebServer/Documents/pdf.py
pdf = subprocess.Popen(convertargs, stdout=subprocess.PIPE): /Library/WebServer/Documents/pdf.py
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__: /Library/WebServer/Documents/pdf.py
errread, errwrite): /Library/WebServer/Documents/pdf.py
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child: /Library/WebServer/Documents/pdf.py
raise child_exception: /Library/WebServer/Documents/pdf.py
OSError: [Errno 2] No such file or directory: /Library/WebServer/Documents/pdf.py
subprocess.Popen
找不到 convert
,可能是因为网络服务器使用了不同的 $PATH。尝试将完整路径提供给 convert
而不是 convert
.