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 version 8.6 or higher.

If pdf4tcl does not work on your system, please add a bug report at the project page or (preferably) make it work and send in a patch.

Features

pdf4tcl is now version 0.9.4. For now you can create pdf files with these features and objects:

Missing Features

Most privitives needed are there, what is needed now are higher level functions to help structuring documents. E.g. header/footer, tables, bulleted lists, etc.

Changes

See Changes page

Usage

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

# import pdf4tcl
package require pdf4tcl

# create a pdf object
pdf4tcl::new mypdf -paper a4 -margin 15mm

# add the first page
mypdf startPage
set width [lindex [mypdf getDrawableArea] 0]

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

# draw some text
mypdf setFont 8 Helvetica
mypdf text "sample text" -x 0 -y 12

# use another font and draw centered text
mypdf setFont 12 "Helvetica-Bold"
mypdf text "Sample Heading" -align center -x [expr {$width/2.0}] -y 12 

# and some right aligned text
mypdf setFont 8 Helvetica
mypdf text "page 1" -align right -x $width -y 12

# 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 -filled 1

# set some justified text into this box
mypdf setFillColor 0 0 0
mypdf drawTextBox 21 51 299 99 "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 destroy

The resulting pdf file is mypdf.pdf.

Installation

Please download pdf4tcl from the Project page. Unpack the archive in a path, where tcl can find the package or set auto_path in your scripts accordingly.

Documentation

Manual

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 and up 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 at the Project page.

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