Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reportlab hello world with an image, bulleted list, and enumerated list.
"""
Reportlab sandbox.
"""
from reportlab.lib.enums import TA_JUSTIFY
from reportlab.lib.pagesizes import letter, landscape
from reportlab.lib.enums import TA_JUSTIFY
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
doc = SimpleDocTemplate("form_letter.pdf",pagesize=landscape(letter),
rightMargin=72,leftMargin=72,
topMargin=72,bottomMargin=18)
styles = getSampleStyleSheet()
styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
Story=[]
logo = "image.png"
# We really want to scale the image to fit in a box and keep proportions.
im = Image(logo, 3*inch, 3*inch)
Story.append(im)
#ptext = '<font size=12>Some text</font>'
#Story.append(Paragraph(ptext, styles["Normal"]))
ptext = '''
<seq>. </seq>Some Text<br/>
<seq>. </seq>Some more test Text
'''
Story.append(Paragraph(ptext, styles["Bullet"]))
ptext='<bullet>&bull;</bullet>Some Text'
Story.append(Paragraph(ptext, styles["Bullet"]))
doc.build(Story)
@shubhamyedage

This comment has been minimized.

Copy link

commented Jun 22, 2017

Hey I am building pdf with same approach. Is there any way to add space before text at new line by providing some value?

@Ronald-Saunfe

This comment has been minimized.

Copy link

commented May 17, 2018

Yes you can use spacers like this
Story.append(Spacer(1,0.2*inch))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.