-2
私は、事前に作成したPDFフォームにデータベースデータを入力して、それを平坦化しようとしています。たとえば、ユーザーが "name"というフィールドを入力した場合は、pdfフォームのnameフィールドに配置する必要があります。Django/PythonでPDFフォームを記入するには?
私は、事前に作成したPDFフォームにデータベースデータを入力して、それを平坦化しようとしています。たとえば、ユーザーが "name"というフィールドを入力した場合は、pdfフォームのnameフィールドに配置する必要があります。Django/PythonでPDFフォームを記入するには?
あなたはDjangoのビューでcombinaisonでreportlab
ライブラリを使用することができます。
from io import BytesIO
from reportlab.pdfgen import canvas
from django.http import HttpResponse
def some_view(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
buffer = BytesIO()
# Create the PDF object, using the BytesIO object as its "file."
p = canvas.Canvas(buffer)
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of functionality.
p.drawString(100, 100, "Hello world.")
# Close the PDF object cleanly.
p.showPage()
p.save()
# Get the value of the BytesIO buffer and write it to the response.
pdf = buffer.getvalue()
buffer.close()
response.write(pdf)
return response
Djangoのドキュメント:https://docs.djangoproject.com/en/1.9/howto/outputting-pdf/
ReportLabのドキュメント:あなたはhttp://www.reportlab.com/documentation/
を達成どこまで?いくつかのコードを表示できますか? –