reportlab工具 直接生成pdf
安装 ReportLab
=================
从 http://www.reportlab.org/downloads.html下载然后安装 ReportLab .
在你的 Python 解释器中通过导入该模块检验它是否安装成功::
>>> import reportlab
如果上面这个命令没有引发任何错误,恭喜,你安装成功了!
Write your view
===============
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(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=somefilename.pdf'
# Create the PDF object, using the response object as its "file."
p = canvas.Canvas(response)
# 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, and we're done.
p.showPage()
p.save()
return response
添加url,测试.
posted on 2009-07-21 16:19 blueoceanli 阅读(699) 评论(0) 收藏 举报
浙公网安备 33010602011771号