Paragraph

Adding Paragraph text to PDF by Python ReportLab with style properties, layout and formats


We can import Paragraph and ParagraphStyle
from reportlab.lib.styles import ParagraphStyle
from reportlab.platypus import Paragraph
Paragraph
We can declare a set of style properties
my_Style=ParagraphStyle('My Para style',
fontName='Times-Roman',
backColor='#F1F1F1',
fontSize=16,
borderColor='#FFFF00',
borderWidth=2,
borderPadding=(20,20,20),
leading=20,
alignment=0
)
Alignment of Paragraph text
Connect this style properties to our paragraph like this.
p1=Paragraph(''' my text here ''', my_Style)

Layout

Layout of Paragraph on Canvas

We have delcared a Canvas like this .
my_path='G:\\My drive\\testing\\pypdf2\\my_pdf.pdf' 
c = canvas.Canvas(my_path, pagesize=A4)
Place our Paragraph on the canvas like this.
p1.wrapOn(c,300,50)
p1.drawOn(c,width-450,height-350)

c.save()
Full code is here
from reportlab.pdfgen import canvas
from reportlab.lib.styles import ParagraphStyle
from reportlab.platypus import Paragraph
from reportlab.lib.pagesizes import  A4

my_Style=ParagraphStyle('My Para style',
fontName='Times-Roman',
backColor='#F1F1F1',
fontSize=16,
borderColor='#FFFF00',
borderWidth=2,
borderPadding=(20,20,20),
leading=20,
alignment=0
)

width,height=A4
my_path='G:\\My drive\\testing\\pypdf2\\my_pdf.pdf' 
c = canvas.Canvas(my_path, pagesize=A4)

p1=Paragraph('''<b>About this online classes </b><BR/>\
     Welcome to our online classes.<BR/> \
	 You can learn Python, PHP, database like MySQL \
SQLite and many more \
<font face="times" color="blue">We are creating \
PDF by using ReportLab</font> \
<i>This is part of our Final report.</i>''',my_Style)

p1.wrapOn(c,300,50)
p1.drawOn(c,width-450,height-350)
c.save()

PDF Mark sheet by using data from SQLite database
PDF

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    26-11-2023

    how can you continue your paragraph on next page if it doesnt end on that page of A4 size

    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer