html文件嵌入到reportlab,使用HTML的Django Reportlab

大家好,我正试着用pythondjango制作一个小PDF使用reportlab库我已经做了一些仅包含一些文本的PDF,但是我不知道如何使用html,我想知道你们是否可以给我一个使用

Hello

之类的东西的示例,因为如果我使用drawString,它会显示'

HELLO

"

让我告诉你我的来源。在from reportlab.pdfgen import canvas

from django.http import HttpResponse

from reportlab.lib.pagesizes import letter

from reportlab.lib.utils import ImageReader

import os

from io import BytesIO

import PIL.Image

def index(request):

return HttpResponse('Hola Marcos :D')

def reporte(request):

# Create the HttpResponse object with the appropriate PDF headers.

response = HttpResponse(content_type='application/pdf')

response['Content-Disposition'] = 'attachment; filename="informe.pdf"'

# Create the PDF object, using the response object as its "file."

buffer = BytesIO()

p = canvas.Canvas(response, pagesize=letter)

logo = ImageReader('http://django-unfriendly.readthedocs.io/en/latest/_static/img/python-logo-256.png')

numero =150

uno = 204 - numero

dos = uno

p.drawImage(logo, 250, 500,uno,dos, mask='auto')

p.setLineWidth(.1)

p.setFont('Helvetica',22)

p.drawString(30,750,'Company')

p.setFont('Helvetica',22)

p.drawString(30,725,'Report')

p.setFont('Helvetica-Bold', 12)

p.drawString(480,759,"7/01/1986")

p.line(460,747,560,747)

# Draw things on the PDF. Here's where the PDF generation happens.

# See the ReportLab documentation for the full list of functionality.

suma = (7*75675678567856785)*70+2*9090

suma = str(suma)

resta = 100-9

resta = str(resta)

p.drawString(100, 630, 'Este podria ser el primer informe de empresa con python Django')

p.drawString(100, 600, suma)

p.drawString(100, 590, resta)

p.drawString(100, 570, 'O2A5X1996A3B4B4A6')

# Close the PDF object cleanly, and we're done.

p.showPage()

p.save()

pdf = buffer.getvalue()

buffer.close()

response.write(pdf)

return response

# Create your views here.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值