2008-05-28

PDF support for Squeak

Yesterday I tried the LibHARU binding for squeak by Torsten.
http://lists.squeakfoundation.org/pipermail/squeak-dev/2008-May/128897.html
It's a low level PDF library (no advanced text flows) but supports color images (PNG).

Getting started is easy, once the PDF document model is clear:
After loading FFI and HPDF and putting libhpdf.dll next to squeak,
put an image in the squeak directory and run the following code in a workspace:
|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'
It creates a pdf document in the squeak directory containing a single page with a 2 by 2 inch image 1 inch from the lower left corner.