Getting Help Language: zh-hans Documentation version: 5.0 如何创建 PDF 文件¶ 本文介绍如何用 Django 的视图动态输出 PDF 文件。该功能由绝佳的开源 ReportLab Python PDF 库提供。动态生成 PDF 文件的优点是你可以为不同的目的创建不同的自定义 PDF——例如,为不同的用户或内容的不同片段生成 PDF。
# 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 ...
这篇文档阐述了如何通过使用Django视图动态输出PDF。这可以通过一个出色的、开源的PythonPDF库ReportLab来实现。 动态生成PDF文件的优点是,你可以为不同目的创建自定义的PDF – 这就是说,为不同的用户或者不同的内容。 例如,Django在kusports.com上用来为那些参加March Madness比赛的人,生成自定义的,便于打印的 NCAA...
Django’s documentation uses theSphinxdocumentation system, which in turn is based ondocutils. The basic idea is that lightly-formatted plain-text documentation is transformed into HTML, PDF, and any other output format. Sphinx includes asphinx-buildcommand for turning reStructuredText into other forma...
# 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 ...
Read the analytics documentation (and how to opt-out) here: https://docs.brew .sh/Analytics.html Next steps: - Run `brew help` to get started - Further documentation: https://docs.brew .sh Python 3: brew install python3 macOSpython 2python 3 Python 2 python Python 3 python3 9 ...
# 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 StringIO buffer and write it to the response. ...
()#Create the PDF object, using the StringIO object as its "file."p =canvas.Canvas(temp)#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 ...
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...
5 documentation Getting started Writing your first Django app part 4 Download Offline Django 1 5 HTML PDF ePub Provided by Read the Docs HomeDownloadDocumentationWeblogCommunityCode Writing your fi rst Django app part 4 Django documentation Django13 3 29 5 does something with it Remember in ...