from reportlab.platypus import SimpleDocTemplate, Paragraph from reportlab.lib.styles import getSampleStyleSheet doc = SimpleDocTemplate("example.pdf") styles = getSampleStyleSheet() text = "Hello World!" para = Paragraph(text, styles["Normal"]) doc.build([para])
from reportlab.lib.pagesizes import letter from reportlab.lib.units import inch from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer doc = SimpleDocTemplate("example.pdf", pagesize=letter, rightMargin=72, leftMargin=72, topMargin=72, bottomMargin=18) paragraphs = [] styles = getSampleStyleSheet() text = "This is some sample text." for i in range(10): paragraphs.append(Paragraph(text, styles["Normal"])) paragraphs.append(Spacer(1,0.2*inch)) doc.build(paragraphs)This example creates a new PDF document named "example.pdf" with the page size "letter" and custom margins. It then adds 10 paragraphs of sample text to the document with a spacer in between each paragraph to create some space. In summary, Python reportlab.platypus SimpleDocTemplate is a package library for quickly and easily creating PDF documents with various elements like paragraphs, tables, images, and more.