Python Forum

Full Version: Using Reportlab to create a landscape pdf
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to create a pdf in landscape format, but I couldn't do it with some of things that I found on the internet. I don't know if they're not useful nowadays or I'm doing wrong.
from reportlab.lib.pagesizes import landscape,A4
from reportlab.pdfgen import canvas

pdf = canvas.Canvas("Training.pdf")
canvas.Canvas.setPageSize(pdf, (landscape(A4)))
pdf.drawString(10,800, 'Hello')
pdf.save()
I also tried to use "pagesize" or "size" and to use other formats.

from reportlab.lib.pagesizes import landscape,A4
from reportlab.pdfgen import canvas

pdf = canvas.Canvas("Training.pdf")
canvas.Canvas.setPageSize(pdf, pagesize=(landscape(A4)))
pdf.drawString(10,800, 'Hello')
pdf.save()
I don't see anything wrong with your first snippet, except the coordinates seem to be out of bounds. If I change it from 10,800 to 10,500, the text is rendered on a landscape page.
(Aug-07-2020, 05:42 AM)bowlofred Wrote: [ -> ]I don't see anything wrong with your first snippet, except the coordinates seem to be out of bounds. If I change it from 10,800 to 10,500, the text is rendered on a landscape page.

Oh, it was just it. Thanks!