pdf4tcl

pdf4tcl is a tcl package for generating pdf files. It started as a port of pdf4php to the tcl language.

pdf4tcl does not contain any binary code, so it should run without modification on any system, which has a tcl interpreter. I tested pdf4tcl on W2k with ActiveTcl-8.4.6, Debian GNU/Linux 3.1 (sarge) with tcl-8.4.7 and tclkit-8.4.6 on W2k and Debian 3.1.

If pdf4tcl does not work on your system, please drop me a mail or (preferably) make it work and send me a patch.

Features

pdf4tcl is now version 0.2, so don't expect too much. For now you can create pdf files with these features and objects:

Usage

Here is a commented example, which should illustrate, how pdf4tcl can be used:

# import pdf4tcl
package require pdf4tcl

# create a pdf object and equally named procedure in global namespace
pdf4tcl::new mypdf -compress 1 -paper a4

# add the first page
mypdf startPage

# draw a line, coordinates start in upper left corner of the paper,
# unit is postscript point, which is 1/72 inch
mypdf line 20 20 560 20

# draw some text
mypdf setFont 8 Helvetica
mypdf drawTextAt 20 32 "sample text"

# use another font and draw centered text
mypdf setFont 12 "Helvetica-Bold"
mypdf drawTextAt [expr {595/2.0}] 32 "Sample Heading" -align center

# and some right aligned text
mypdf setFont 8 Helvetica
mypdf drawTextAt 575 32 "page 1" -align right

# draw a rectangle with dashed red outline and lightgrey fill colour
mypdf setLineStyle 0.5 8 4
mypdf setStrokeColor 0.8 0 0
mypdf setFillColor 0.9 0.9 0.9
mypdf rectangle 20 50 300 100

# set some justified text into this box
mypdf setFillColor 0 0 0
mypdf setStrokeColor 0 0 0
mypdf drawTextBox 22 60 296 96 "This is just some senseless sample text,\
	illustrating some features of pdf4tcl. This text should be justified\
	by stretching white space between words, to make for straight left\
	and right margins." -align justify

# write pdf to a file
mypdf write -file mypdf.pdf

# cleanup memory and unset procedures and variables
mypdf cleanup

The resulting pdf file is mypdf.pdf.

Installation

Please download pdf4tcl from this page. The content of the unix and windows version are the same, only the format of the file archive differs.
Unix/Linux: pdf4tcl-0.2.tar.gz
Windows: pdf4tcl-0.2.zip
Unpack the archive in a path, where tcl can find the package or set auto_path in your scripts accordingly.

Documentation

This is still to be done. Please use the usage example above and the scripts in the example directory of the package archive for now.

Copying, Feedback and further development

Thanks to contributions of Jens Pönisch version 0.2 of pdf4tcl has support for additional graphical elements, like circles, curves and arcs. It is now possible to build a page "bottom-up" with coordinate origin in lower left corner of the paper. You can still use it "top-down", with origin in upper left corner.

pdf4tcl version 0.2 is licenced like tcllib and many other tcl extensions using a BSD-like licence. See licence.txt for details.

pdf4tcl version 0.1 had been released under the GNU Public Licence. This version is still available as pdf4tcl-0.1.tar.gz.

There is much room for enhancing pdf4tcl. I'd really like to get feedback, suggestions and patches.

I'm working on a package pdfreport, which will encapsulate pdf4tcl and provide a really simple interface for generating standard database reports.