http://www.python.org/workshops/2000-01/proceedings/posters/robinson/robinson.pdf
http://www.ibm.com/developerworks/linux/library/l-sc6.html?loc=dwmain
http://www.reportlab.com/i18n/python_unicode_tutorial.html
http://www.reportlab.com/docs/reference.pdf
Install
apt-get update apt-get install python-reportlab
Examples
Hello world
from reportlab.pdfgen import canvas from reportlab.lib.units import inch font = "Helvetica" font_size = 26 text = "Hello, world" x = 5.0 * inch y = 8.0 * inch destination_file = "/tmp/first.pdf" my_canvas = canvas.Canvas(destination_file) my_canvas.setFont(font, font_size) my_canvas.drawRightString(x, y, text) my_canvas.save()
example 2
http://plug.linux.org.au/events/seminar/2004-05-files/plug_rl_presentation.pdf examples: http://www.plug.org.au/events/seminar/2004-05-files/plug_rl_presentation.tar.bz2
http://wiki.w4py.org/pdf-creation-with-reportlab.html
xml to pdf
build xml or xhtml file based on my layout, then use some template language to fill in the values, then finally pass the results to reportlab and get a pdf. READ Ch5 of userguide of report lab >>> from elementtree import ElementTree >>> from reportlab.lib import styles >>> from reportlab.lib import units >>> from reportlab.platypus import * >>> letter="""<doc> ... <para>${applicant.prefix} ${applicant.full_name()}<br/> ... ${applicant.address1}<br/> ... #if $applicant.address2 != None ... ${applicant.address2}<br/> ... #end if ... ${applicant.city}, ${applicant.state} ${applicant.postal}</para> ... ... <para>Dear ${applicant.prefix} ${applicant.full_name()}:</para> ... ... <para>Your application rose to the top of the millions and millions that we ... received. We are pleased to extend to you a position on our dynamic team.</para> ... ... <para>We will come for you in the night, unannounced. Be prepared.</para> ... ... <para><i>Congratulations!</i></para> ... ... <para>The Board<br/> ... Non Compos Mentis Research</para> ... </doc>""" >>> document=SimpleDocTemplate(open("itcoutput.pdf","w")) >>> components=[] >>> sheets=styles.getSampleStypeSheet() Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute 'getSampleStypeSheet' >>> sheets=styles.getSampleStyleSheet() >>> paragraphStyle=sheets['Normal']
doc=ElementTree.XML(letter)
>>> for para in doc.findall('para'): ... components.append(Paragraph(ElementTree.tostring(para),paragraphStyle,None)) ... >>> components.append(PageBreak()) >>> document.build(components) >>> open("itcoutput.pdf","w").close()