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.


Documentation

The package ships that manual page, tclpdf(n), covering every command.

The source archive adds the test suite and 81 examples, which between them write 90 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, 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. Three of them depend on the machine rather than on the package and skip themselves where it cannot serve them - the canvas example needs Tk, which tclpdf never loads and does not require; the Noto half of the emoji example needs a 25 MB face under a licence of its own, which is therefore not versioned here; and its Apple half needs Apple Color Emoji, which ships with macOS and exists nowhere else. A machine without any of the three writes 87 documents instead of 90. 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

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.