私はこれと非常によく似た質問をしています。Django の Ubuntu サーバーで wkhtmltopdf を使用して pdf を作成しています。
from tempfile import *
from subprocess import Popen, PIPE
tempfile = gettempdir()+"/results.pdf"
papersize = 'Tabloid'
orientation = 'Landscape'
command_args = "wkhtmltopdf -O %s -s %s -T 0 -R 0 -B 0 -L 0 http://pdfurl %s" %(orientation, papersize, tempfile)
popen = Popen(command_args, stdout=PIPE, stderr=PIPE)
pdf_contents = popen.stdout().read()
popen.terminate()
popen.wait()
response = HttpResponse(pdf_contents, mimetype='application/pdf')
return response
これにより、 popen = Popen... 行に「そのようなファイルまたはディレクトリはありません」というエラーが表示されます。だから私はその行を
popen = Popen(["sh", "-c", command_args], stdout=PIPE, stderr=PIPE)
そして今、pdf_contents =... 行に「'file' object is not callable」というエラーが表示されます。
また、 popen =... 行に .communicate() を追加しようとしましたが、その方法で pdf 出力を見つけることができないようです。command_args 行をコマンド ラインに入力すると、問題なく pdf が作成されることを追加する必要があります。誰かが私を正しい方向に向けることができますか?