2017-12-23 7 views
0

は、私はPDFが自分のウェブサイトに生成するが、私のシステムにダウンロードしないように取得することができますジャンゴ2.0とPython 3Docraptor API DjangoはPDFが

でDocraptorを使用しようとしていますダウンロードして取得します。ここで

は、PDFファイルをダウンロードするために変更する必要がある何https://github.com/DocRaptor/docraptor-python

から自分のコードですか?

doc_api = docraptor.DocApi() 

try: 

    create_response = doc_api.create_doc({ 
    "test": True,  
    "document_content": "<html><body>Hello World</body></html>", 
    "name": "docraptor-python.pdf", 
    "document_type": "pdf",  

    }) 
    file = open("/tmp/docraptor-python.pdf", "wb") 
    file.write(create_response) 
    file.close() 
    print("Wrote PDF to /tmp/docraptor-python.pdf") 

except docraptor.rest.ApiException as error: 
    print(error) 
    print(error.message) 
    print(error.code) 
    print(error.response_body) 

私はいくつかの種類のHttpResponseが見つからないと思いますか?

これは、この問題を克服すると、PDFファイルを作成するのに最適な方法です。彼らの技術サポートは素晴らしいですが、ドキュメンテーションは少し不足しています。

ありがとうございました。

答えて

2

はい、応答がありません。一般的には次のようなものです:

response = HttpResponse() 
response['Content-Type'] = 'application/pdf' 
response['Content-Disposition'] = 'attachment; filename="my_pdf.pdf"' 
response.write(creeate_response) 
return response 
+0

素晴らしいです。どうもありがとうございました。 – diogenes

関連する問題