I need a new line, so I can see a format in the PFD, I try to do it adding a page width but it didn work, I use an other thing with /n and it didn't work nither. This is my code. I can add a format manualy cause I need to show information that a get from the database and I get the information in one long line.
def PdfReportView(request):
print id
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'filename="PatientReport.pdf"'
c = canvas.Canvas(response, pagesize=letter)
t = c.beginText()
t.setFont('Helvetica-Bold', 10)
t.setCharSpace(3)
t.setTextOrigin(50, 700)
t.textLine("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.")
c.drawText(t)
c.showPage()
c.save()
return response
You can use textLines()
if you have \n
in your text input:
t.textLines('''Lorem Ipsum is simply dummy text of the printing and
typesetting industry. Lorem Ipsum has been the industry's standard dummy text
ever since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book.''')
if your text is one line, you can use textwrap
module to break it to several lines:
from textwrap import wrap
text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."
wraped_text = "\n".join(wrap(text, 80)) # 80 is line width
t.textLines(wraped_text)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With