from reportlab.pdfgen.canvas import Canvas # create a new PDF file pdf = Canvas('example.pdf') # add some text pdf.drawString(100, 750, "Welcome to ReportLab!") # save the PDF file pdf.save()
from reportlab.pdfgen.canvas import Canvas from reportlab.lib.pagesizes import letter # create a new PDF file pdf = Canvas('example.pdf', pagesize=letter) # draw a rectangle pdf.rect(100, 650, 200, 100) # draw a circle pdf.circle(400, 500, 50) # save the PDF file pdf.save()
from reportlab.pdfgen.canvas import Canvas # create a new PDF file pdf = Canvas('example.pdf') # draw an image pdf.drawImage('example.png', 100, 100) # save the PDF file pdf.save()Overall, the Python reportlab.pdfgen.canvas package is a powerful tool for creating PDF files in Python. It provides various methods to add text, shapes, images, and other elements to the PDF document.