本文介绍了Django ReportLab:使用Drawing对象创建PDF并通过Httpresponse返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ReportLab中,绘图对象可以写入不同的渲染器,例如

  d = shapes.Drawing(400,400) 
renderPDF.drawToFile(d,'test.pdf')

对象可以通过httpresponse发送,例如:

  response = HttpResponse(mimetype ='application / pdf')
['Content-Disposition'] ='filename = test.pdf'
c = canvas.Canvas(response)

在我的情况下,我的问题是,我有一个reportLab脚本使用绘图对象,保存到本地文件系统。我现在把它放在Django视图中,并想知道是否有一种方法不保存到本地文件系统,而是发送回客户端。



我希望我描述这个问题



感谢您的任何意见!



更新 b
$ b

原来在renderPDF中有一个函数:

  renderPDF.draw canvas,x,y)

可以在给定的canvas中渲染drawing >

解决方案

原来在renderPDF中有一个函数:



renderPDF.draw (drawing,canvas,x,y)
它可以在给定的canvas中渲染drawing()对象。


In ReportLab, Drawing object can be written into different renderers, e.g

d = shapes.Drawing(400, 400)
renderPDF.drawToFile(d, 'test.pdf')

and in Django, Canvas object can be sent via httpresponse, e.g.:

response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'filename=test.pdf'
c = canvas.Canvas(response)

in my case, my problem is that I have a reportLab script using Drawing object which saves to local file system. I now put it in Django views, and wondering whether there is a way to not save to local file system but instead sent back to client.

I hope I describe this question clearly.

Thanks for any advice!

updates

it turns out there is a function in renderPDF:

renderPDF.draw(drawing, canvas, x, y)

which can render drawing() object in the given canvas.

解决方案

it turns out there is a function in renderPDF:

renderPDF.draw(drawing, canvas, x, y)which can render drawing() object in the given canvas.

这篇关于Django ReportLab:使用Drawing对象创建PDF并通过Httpresponse返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 11:49