编程语言
首页 > 编程语言> > python-将图形添加到Reportlab PDF

python-将图形添加到Reportlab PDF

作者:互联网

我已经看到了许多reportlab图形示例.生成图形不是问题,我似乎无法弄清楚如何在pdf上显示图形.

这是代码:

buffer = StringIO()
p = canvas.Canvas(buffer, pagesize = letter)

##### Beginning of code in question

d = Drawing(200, 100)
pc = Pie()
pc.x = 65
pc.y = 15
pc.width = 70
pc.height = 70
pc.data = [10,20,30,40,50,60]
pc.labels = ['a','b','c','d','e','f']
pc.slices.strokeWidth=0.5
pc.slices[3].popout = 10
pc.slices[3].strokeWidth = 2
pc.slices[3].strokeDashArray = [2,2]
pc.slices[3].labelRadius = 1.75
pc.slices[3].fontColor = colors.red
d.add(pc)

p.drawPath(d) ### THIS DOES NOT WORK, but need something similar

#####End of Code in Question

p.showPage() #Page Two

p.save() # Saves the PDF and Returns with Response\

pdf = buffer.getvalue()
buffer.close()
response.write(pdf)
return response

这就是我显示文字的方式.
p.setFillColorRGB(1,1,1)
    标头= p.beginText(100,765)
    header.textLine(“页面标题文本”)
    p.drawText(标题)

解决方法:

我之前写过这篇文章,但它一直是该网站上最受欢迎的文章之一,因此我认为它对某些人有用.

http://www.protocolostomy.com/2008/10/22/generating-reports-with-charts-using-python-reportlab/

如果这还不足以让您顺利完成工作,请告诉我,如果我有更多时间,我会稍后再提供帮助.

标签:reportlab,graph,python,django
来源: https://codeday.me/bug/20191105/1997766.html