Version 43 of PDF

Updated 2008-02-11 00:56:06 by sg

PDF is an initialism (versus an acronym, which is slightly different [L1 ]) for "Portable Document Format", a file format created by Adobe [L2 ]. CL maintains a page [L3 ] on the subject.

While there's no Tcl-specific broadly-applicable PDF library as of summer 2003, PDFlib [L4 ] supports Tcl among several other language bindings. Notice at the heart of PDFlib's licensing [L5 ] this summary: "You may test and fully include our software in your projects, but you need a valid license key to remove the 'www.pdflib.com' demo stamp on all generated pages."

Perl and Python have much stronger PDF stories to tell (see [L6 ], for example), and, of course, Tcl has ways to exploit anything available through those languages, including Tclperl and Tclpython.


Clif Flynt worked on generating PDFs from Tcl.

Lars H has written a pure Tcl package writepdf (see [L7 ] and its parent directory) that can generate well-formed PDF files. The API is roughly at the same level of abstraction as writing raw postscript with puts, so you need to be familiar with the PDF specification to use it.

It would be great to have something sitting on top of writepdf which can generate correct pdf from a text widget and a canvas...It seems like this ought to be possible in pure Tcl.

Lars H: It is certainly possible (at least to the same extent as the analogous generation of PS files). I suspect the main difficulty would be how to handle text, or more precisely, select a font that matches that used in the original widget. My more immediate interest was otherwise to be able to use PDF as an "export format" for graphics not really having anything to do with Tk, but I don't know when I can return to even that part of the project.


2003-11-25 VI The PDF specifications are at http://partners.adobe.com/asn/tech/pdf/specifications.jsp

While there are relatively few direct Tcl-PDF connections as of late 2001, "pdf417_encode [L8 ] converts ASCII strings into pdf417 barcode". NOTE: PDF417 barcodes have nothing whatsoever to do with Adobe's Portable Document Format.


 What: Tclhpdf
 Where: http://reddog.s35.xrea.com/wiki/tclhpdf.html
 Description: Tcl interface to HARU Free PDF Library
 Updated: 09/2007 (Added by Roy Terry see comp.lang.tcl posting: 22Sep07)
 Contact: [email protected]

 What: TEItools
 Where: http://xtalk.price.ru/SGML/TEItools/
 Description: Collection of Tcl and other tool scripts used for
        transforming SGML documents to various other formats.  Currently
        supports HTML, LaTeX2e, RTF, PS, and PDF.  Uses CoST.
 Updated: 04/1998
 Contact: mailto:[email protected]

 What:  WELD
 Where: http://www.javafoundry.com/javapdf
 Description: Web Enabled Logic Documents (WELD) make use of Jacl/Tcl to
        provide the ability to hold WWW applications together.  WELD is
        a part of JavaPDF (the open source servlet utilities project).
 Updated: 08/2001
 Contact: mailto:[email protected] (Lee T  Hall)

 What: pdflib
 Where: http://www.pdflib.com/
 Description: PDFLib is an ANSI C library for creating new PDF files.
        Bindings for a number of languages, including Tcl, are available.
        This package is not designed to access and update existing PDF
        files.
 Updated: 11/1999
 Contact: mailto:[email protected]

Sven Sass's employer generates PDF by way of Java classes converting Docbook to FO to PDF (!).


The most immediate contact between PDF and Tk probably is by way of PS, the "output" format for canvases. Clif Flynt has "a subset of a Tcl canvas->PDF script ... [which] does lines, text, and nested canvases" in the starkit at http://noucorp.com/postcard .

Another well-worn pathway involves transforming HTML to PDF.


GS (031129) There is a simple C source code to convert text file in PDF at http://wwwvms.mppmu.mpg.de/vmssig/src/c/TXT2PDF.C


2004-01-13 VI There are two problems I face. One is that PDF is page based (like PostScript), so pagination is the application's headache. Add headers, footers, tables that span pages, and this soon gets to be like a mini typesetting program. Doing a canvas on one page (modulo the next para) or a text widget onto one page seems doable.

The other is that I haven't figured out how to wrap text consistently. e.g. if a text item uses the -width option in the canvas, then I don't know how to decide where to break the text. I have read about this, and I've heard that this is possible in 8.4.5 or 8.5, but I still don't know how.


Frank Richter did a pure tcl package pdf4tcl (see [L9 ]), which started as a port of pdf4php. It has a tclish and easy to use interface, but does only support a subset of pdf features. pdf4tcl is now version 0.2, supports additional pdf objects and licence changed to BSD.


Googie - Image Magick contains import tool, which can be executed by exec, so we can import wish window and save it as PDF. We can also use TclMagick instead of exec.


Mac Cody - Trampoline! aims to provide a means to export the contents of a canvas widget to a PDF document (see [L10 ]). The internal procedures within Trampoline! can also be used to generate PDF documents without Tk being present. The plan is to eventually split Trampoline! into two separate packages. Trampoline! will contain the Tk-dependent components that will call another package, called TclPDF, that will contain Tk-independent functionalities for generating PDF documents.


The Mathematical Orchid - Does anybody know of a pure Tcl tool to read PDF files? (For diagnostic purposes. I have a PDF file here that Acrobat can't open; even the newest version. But the author claims "it works fine on my PC".)

As far as I know, Tcl is able to handle binary files, so it should in principle be possible to do something like this. The only real difficuly is that parts of the file can be encrypted and/or compressed. (Anybody ever wrote a pure Tcl DEFLATE decompressor?)

Orchid, CL works often with PDF (and the people who work with PDF), and I suspect there's a problem "upstream". Briefly, no, Tcl doesn't read PDF in the sense I believe you mean. You're welcome to e-mail or join the Chat, for more detailed advice.

Lars H: A practical advice (if you can't fix the problem upstream) is to try a different PDF viewer (e.g. ghostscript can handle not only postscript but also PDF, to mention the most cross-platform one). In my early experiments with generating PDF the files used to be viewable in everything I tried except Acrobat, and the error messages gave no information. (Later PDF specifications more properly described the issue that Acrobat got hung up on, though, so I managed to fix it.)

DKF: Check that the PDF file has been downloaded correctly. If it was downloaded as text, there can be corruption of the contents (which, unlike PostScript, are binary).

The Mathematical Orchid: Already tried Ghostscript. Gives me some error about "JavaScript is required". The problem is a PDF file with some diagrams which refuse to display. (Half the diagram shows up, then some cryptic error message.) Downloaded several times, still won't display. Author insists they display with his copy of Acrobat. I'm guessing they have some extra software or something that they've forgetten they have. Well anyway, I've read the PDF spec (and the PS one, actually), so maybe I'll have a go at writing something myself. (As I say, I can read the file in Notepad, but the FLATE compressed parts are a tad difficult to follow. Most of a PDF file is actually plain ASCII until you compress it...)

IDG Recent versions of acrobat have javascript built in, but it can be turned off in the preferences menu. Do you have an old version, or have you got javascript turned off?

schlenk: Decoding the pdf stream isn't very hard, but your right that the compression is one thing that needs a bit more work, the rest is straight forward, unless you have edited pdfs with newer dicts. I have an example that reads PDF metadata with Tcl somewhere (need to search it...), was two hours work or so.


KPV: See also Text2PDF and Parsing PDF.


Category Acronym | Category Documentation