Skip to content

Instantly share code, notes, and snippets.

@abubelinha
Forked from cwebber314/reportlab_hello.py
Created January 3, 2022 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abubelinha/7167546015540284c194ea25bfe5ec84 to your computer and use it in GitHub Desktop.
Save abubelinha/7167546015540284c194ea25bfe5ec84 to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment