This recipe shows how to publish data from the Firebird RDBMS to PDF, using the xtopdf toolkit and the fbd Python driver for Firebird. Firebird is a cross-platform, open source RDBMS based on the former Interbase RDBMS from Borland, which they used to bundle with some of their developmemt tools, such as Borland C++ and Borland Delphi.
The recipe reads data from a Firebird table, using the fbd Python driver for Firebird, and writes it to PDF, using the xtopdf toolkit. See:
http://jugad2.blogspot.in/p/xtopdf-pdf-creation-library.html
for information on xtopdf.
It assumes that a Firebird database called test.fdb exists under /temp/firebird (C:\temp\firebird, really - the test was done on Windows), and that it has a contacts table with the structure shown in the code of the recipe.
More details and sample output are here:
http://jugad2.blogspot.in/2014/01/by-vasudev-ram-pdf-firebird-is-cross.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # FirebirdToPDF.py
# Author: Vasudev Ram - http://jugad2.blogspot.com
# Demo program to show how to convert Firebird RDBMS data to PDF.
# Uses xtopdf, Reportlab, Firebird RDBMS and fdb Python driver for Firebird.
import fdb
from PDFWriter import PDFWriter
con = fdb.connect(dsn='localhost:/temp/firebird/test.fdb',
user='dummy', password='dummy')
cur = con.cursor()
select_stmt = 'select * from contacts order by name desc'
cur.execute(select_stmt)
pw = PDFWriter("contacts.pdf")
pw.setFont("Courier", 12)
pw.setHeader("Firebird RDBMS data (contacts.fdb) to PDF")
pw.setFooter("Generated by xtopdf using fdb Firebird driver for Python")
for (id, name, address) in cur:
print id, name, address
pw.writeLine(str(id) + " " + name + " " + address)
pw.close()
# EOF
|
In order to make the recipe work, you have to install Firebird RDBMS, after downloading it from www.firebird.org. You also have to download and install the fbd Python driver for Firebird, from PyPI. The recipe was tested with Firebird v2.5.2 and fdb v1.4.