ReportLab
Revision as of 17:00, 13 November 2012 by Dave Young (talk | contribs)
ReportLab
Following this helpful tutorial
from reportlab.pdfgen import canvas
c = canvas.Canvas("hello.pdf")
c.drawString(100, 100, "Hello WORLD!")
c.save()
Creates a pdf from a .txt file.
#!/usr/bin/py
#gen pdf
from reportlab.lib.pagesizes import letter, A4
from reportlab.pdfgen import canvas
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
doc = SimpleDocTemplate("text.pdf", pagesize=A4,
rightMargin=72, leftMargin=72,
topMargin=72, bottomMargin=18)
content = []
styles = getSampleStyleSheet()
for line in open('file.txt'):
line = line.strip()
if line:
p = Paragraph('<font size=12>'+line+'</font>', styles["Normal"])
content.append(p)
content.append(Spacer(1, 12))
doc.build(content)