Created
January 20, 2014 04:34
-
-
Save cwebber314/8514907 to your computer and use it in GitHub Desktop.
Reportlab hello world with an image, bulleted list, and enumerated list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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>•</bullet>Some Text' | |
Story.append(Paragraph(ptext, styles["Bullet"])) | |
doc.build(Story) |
Yes you can use spacers like this
Story.append(Spacer(1,0.2*inch))
I am building a pdf with an Image to the right and text to its left. But the text is added to the next line of the Image. How can I do the same can anyone help me out in this?
I got my image (logo) justified to the right by using the hAlign parameter following
https://www.kite.com/python/docs/reportlab.platypus.Image
im = Image(file_logo, 0.75*inch, 0.75*inch, hAlign='RIGHT')
flowables.append(im)
Do you know how to add space between table objects? I used "Story.append(Spacer(1,0.2*inch))" mentioned in the above comment but it didn't change anything in the pdf.
@ArjunHS this worked for me:
from reportlab.platypus import Paragraph
Story.append(table1)
Story.append(Paragraph("<br /><br />"))
Story.append(table2)
@abubelinha Thanks for the code. This works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey I am building pdf with same approach. Is there any way to add space before text at new line by providing some value?