0
我有以下代码:打印ImageMagick的转换输出到浏览器
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的转换将图像转换为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
啊!谢谢。使用完整的转换路径解决了这个问题。 –
如果有效,请接受答案 – Julius