Thursday, September 23, 2010

PDF Generation using Smalltalk

Marten Feldtmann is working on pdf creation using libHaru, he published a first, not ready code for a wrapper around libHaru.

But I already wrapped this small library for Pharo/Squeak two years ago with a more natural Smalltalk interface. So one can write:

| document page image |
document := PDFDocument new.
page := document addPage.
image := document loadPNGImage: 'Image.png'.
page drawImage: image rectangle: (Rectangle origin: 72@72 extent: 144@144).
document saveToFile: 'documentWithImage.pdf'

My library is also mentioned as one of the options for generating PDF on the seaside PDF page.

I made the code available at and licensed it with MIT. Would be good if Marten will have a look and maybe port my code to VAST before doing any unnecessary work on his side...

Independent from that I would still like to write/see a PDF framework written in plain Smalltalk (similar to Java's iText).

The more I think about it the more I like the idea:

  • Solutions like using external libraries or frameworks (LibHaru, ApacheFOP, ...) always have limits
  • If any work would be done in Smalltalk one would have full control
  • PDF is a nice document format that is usable on nearly any platform
  • PDF is now more than just text and images - you can have interactive PDF forms, annotations, ...
  • There is no unify way for reporting and printing in current Smalltalks
  • Yes, there is a rough plain Smalltalk PDF Generator from Bruce Badger but the license is AFAIK restricted (I would prefer MIT)
  • it would make up a nice GSOC/CampSmalltalk/Community project
  • Smalltalk streams are much easier to use than Java streams
  • the code would be nicely testable using unit tests

However - time is limited. But if anyone is interested feel free to contact me...

BTW: did you know that Bruno Lowagie (author of iText) changed the license of his Java PDF library to block his government.


rush said...


there is allready some work done on (pure) Smalltalk pdf generation:

But my gut feeling is that implementing full, or at least significant part of pdf specification would be a huge undertaking.

Torsten said...

Yes, but Hans-Martin PDFReader does not write and SPDF is the one from Bruce that I mentioned.

Maybe the one from Dwight could be a base but it's not published.

I know that implementing the whole spec would be a massive amount of work but look at Seaside. It started easy and has grown one step after the other. If there would be enough interest in the community I think it is possible...

rush said...

Well, I would certainly be great to have such Smalltalk library. What worries me is that seems that most of the work that needs to be done, is getting very intimate with the pdf specs, caveats, unwritten usage patterns, and behavior of popular implementations. I see that general implementations like libharu have thrown a lot of energy in that area, and all that would need to be redone for Smalltalk implementation. And realistically, general pdf projects can probably throw much more resources (man hours) at that task than (I am afraid rather small) Smalltalk community.