[reportlab-users] txt2pdf

Carl Karsten carl at personnelware.com
Mon Feb 12 18:41:58 EST 2007


Hi list,

I am trying to make a little txt2pdf example program, ideally about as simple as
the HelloWorld.py - Below is my attempt that does not deal with CR's 'right.'

I see http://www.reportlab.org/devfaq.html#2.3.2 that I could proably make work,
but am hoping for something much simpler to demo how easy it is to glue things
together with python. 50+ lines starts to loose the "it's easy" look.

And yes, I am leaning on the 80/20 rule: 80% of the job is done in the first 20%
of work. 80% of the job is all I want - I don't need all of the fluff that
makes up the final 20% of the job (page numbers, titles.)

Carl K

# txt2pdf.py

import glob
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch

font = "Helvetica"
font_size = 26
x = 5.0 * inch
y = 8.0 * inch

files = glob.glob('*.txt')
for filename in files:
text = open(filename).read()
destination_file = filename[:-4] + ".pdf"
my_canvas = canvas.Canvas(destination_file)
my_canvas.setFont(font, font_size)
my_canvas.drawRightString(x, y, text)
my_canvas.save()


More information about the reportlab-users mailing list