tclpdf

tclpdf
Login

tclpdf

tclpdf - PDF generation for Tcl


Synopsis

Create PDF documents from Tcl: pages, graphics, embedded fonts, images, tables and electronic invoices. A pure Tcl package - no compiler, no binary extension, no Tk.

Beyond the usual page, text and graphics work it does two things a PDF writer often leaves out: general file attachments, and form XObjects that store a drawing once and place it as often as wanted. A document is a TclOO object, every command takes Tcl-style -options, and the topical modules are loaded on first use - a caller who writes text never loads the image code.

Everything listed here is built and tested. Measured against the page count of its chapters that covers roughly a third of ISO 32000-1 - and the missing two thirds are almost entirely what a reader of foreign PDFs needs rather than a writer - reading an encrypted file among them.


Dependencies

There is no other package that tclpdf itself loads. Barcodes look like an exception and are not one: tzint is required by your script rather than by tclpdf - without it there is no barcode, but nothing in this package knows about them or asks for it. What tzint produces is SVG, and svg -data draws it. zlib is a command built into Tcl, not a package, and Tk is never loaded - not for colour names, not for images.

Two releases installed side by side both register their modules, and when both offer the same version of one, Tcl can load the older file. 1.6 kept the numbers of five modules whose contents had changed since an earlier release, so whoever installed 1.6 beside 1.5 takes 1.6.1. After any update, ask where a module came from - after package require tclpdf and a call that loads it, such as a text with -width for textBlock; the answer is the source command with the file's path:

package ifneeded tclpdf::textBlock [package present tclpdf::textBlock]

Documentation

The manual page tclpdf(n), covering every command, is not installed with the package: it travels in the source archive, under doc/, and stands on this wiki as man-page.

The source archive adds the test suite and 88 examples, which between them write 97 documents, starting with a hello-world of ten lines that needs nothing else in the directory: shapes, colour, text layout, attachments, forms, diagonal stamps, flowing text and text along a path, a paragraph and the cells of a table with runs in tags and in Markdown, soft hyphens and leader rows, the type area and text that paginates itself, extending the package from outside, font embedding in four kinds of file, kerning, ligatures, writing systems in eleven faces, missing glyphs, variable fonts, colour fonts in both COLR versions and a real emoji face whose sequences are one glyph each, images, gradients, SVG, labels inside a drawing, barcodes, three kinds of table, two ZUGFeRD invoices and an Order-X order, PDF/A certificates in sRGB, CMYK and grey, two tagged documents, a weakly structured one, an accessible one and a PDF/UA-2 guide, a navigation demo, a letterhead taken over from an existing PDF, a file continued twice by incremental update, two encrypted documents, signed ones: invisible and visible, in one stage and in two, a document signed twice by two people, and a ZUGFeRD invoice that is approved and countersigned - and, in a group of its own, what a Tk canvas holds put on paper as paths rather than as a picture of the screen. Each one is a readable script of its own and says in its header what it is for.

Build them all at once and look at the result:

make examples

That runs every example into examples/out - one PDF each, except for a handful that write more than one: the languages example writes the same page three times - in a standard face, in an embedded one and in a smaller one - and several write the same document twice, once plain and once as PDF/A. Some of them depend on the machine rather than on the package and skip themselves where it cannot serve them - the canvas example 11.01 needs Tk, which tclpdf never loads and does not require; the Noto half of the emoji example 02.18 needs a 25 MB face under a licence of its own, which is therefore not versioned here; its Apple half needs Apple Color Emoji, which ships with macOS and exists nowhere else; the signature example 08.08 needs openssl; and the two timestamp examples 08.06 and 08.07 need either the network or openssl, which stamps them offline through a throwaway authority. A machine writes 91 to 97 documents accordingly. make clean removes the directory again. A single example also runs on its own and takes the output path as its argument:

tclsh examples/00.01-hello-world.tcl hello.pdf

See Also


Copyright (C) 2026 Alexander Schoepe, Bochum, DE

Contributors - special thanks: Ralf Fassel

Tcl package: MIT license. That covers everything the package installs: the Tcl modules, pkgIndex.tcl and the ICC profiles in icc/, which are a runtime part because their bytes end up inside every PDF/A document - sRGB (free of copyright), the ICC's own sRGB2014 under the ICC's terms, and basICColor's ISO Coated v2 CMYK and grey intents under the zlib licence.

No font is part of the package. The faces under examples/assets/fonts are there so that the tests and the examples have something to embed, and they travel in the source archive alone - make install installs no font, and the binary archives contain none. They are third-party work under their own terms, sorted by origin in the source tree: DejaVu (Bitstream Vera licence), the Google Fonts faces - Roboto, Arimo, Bitcount Prop Single, Niconne, Permanent Marker and ten Noto faces (SIL Open Font License 1.1, Permanent Marker Apache 2.0) -, OCR A and OCR B, the URW Core 35 faces, the Liberation faces and Adobe's core AFM metrics, each with its licence beside it. Whether you may embed a font into a PDF that tclpdf writes is a question for that font's licence, not for this one.