大家好,我正试着用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.