Haskell PDF 1.0

Here it is ! I finally released a version 1.0 of my Haskell PDF library. It is a totally new implementation and a totally new version. But, it is not done yet. There are several other features I'd like to introduce in future versions and some things I'd like to improve. But, I had to release something. I could not wait forever.

Here is a summary of the features with some criticisms. The package is containing a demo in the Test folder.

Note before reading : I released a 1.1 version with additional features described in another post.

1. PDF

The PDF is a monad. When you run the monad you specify the default page size, the name of the output file and some other settings for the document. It is not obvious if it has to only be a monad. Perhaps, I'll introduce another API in a future version.

The PDF documents generated by HPDF are compressed by default.

2. Document

A PDF document generated by HPDF can contain several pages. You can specify the size of each page and the transition between the pages (for a slideshow).

At the level of pages, you have access to the draw monad. A draw value can be passed to a page for drawing. You can also create PDF XObjects which are drawings that can be reused in different pages thus decreasing the size of the final PDF. Indeed, if you use the same Draw value in different contexts, you generate the same drawing commands several times. But, if you package the drawing commands in an XObject and then reuse a reference to the XObject, the commands are generated just once and the PDF is smaller and faster to render.

3. Shapes

You can build any shape with paths. But, since it is not very easy to build the most common shapes, you can use the Shape class and the type constructors Rectangle, Ellipse etc ...

You can control the style of the pen, change the clipping region etc...

4. Colors

Colors are always in RGB space. You can specify a color in HSV but it will be mapped to RGB space (not yet tested if the mapping is right). So, when you create a gradient, the interpolation will take place in the RGB space even if you use HSV colors.

You can specify radial and axial gradients.

5. Pattern

A pattern is just a drawing that you can use to fill a shape. A pattern can be uncolored (no color command must be used). Then, you can reuse it with different colors.

Currently, I am not imposing the constraint. In the future, I am thinking about adding a phantom type to the draw monad to detect the use of color operators in the definition of a drawing. Then, I'll be able to discriminate between pure shapes and drawings. Of course, I could also have created a Path monad.

6. Actions

In this version the only action defined is the URL link and to use it you have to create an annotation. I have a lot of remaining work to do on annotations. This version is very limited : you can link to an URL or to another part of the PDF. It is also possible to create text annotations.

7. Media

It is possible to load a jpeg. In the future I'll add PNG and PDF generated by pdftex.

You use an image a bit like an Xobject. An image is a special XObject. That's why an image is defined in the PDF monad and not in the draw monad : it can be shared between several pages.

8. Text

Text is a very complex thing. The current implementation is limited to the 14 standard PDF fonts. But, I am parsing the AFM files and computing the text width using kerning information.

To display text, you need to use the PDFText monad since in PDF a Text section is a bit special. I am providing some functions to allow to quickly display a line of text. But, there is no real typesetting yet. It is planned for a future release.

In short, there is enough to have fun. Future releases will build on this foundation to create more complex things.

9. Criticisms

When I code during my spare time there is only one rule : having fun. So, I too easily switch to a very quick and dirty mode. If you look at the organization of my modules (not the ones visible in the Haddock documentation but the other ones) you'll discover a total chaos. I really need to reorganize everything and be careful about circular references between modules (the cause of the current chaos in my package)

There are lots of features but the level of test is weak. Moreover, the PDF spec is free but its semantic is very fuzzy and none of the PDF reader behave in the same way. I have tested with acrobat reader 8 and Apple preview. It should work with Linux readers too but I have not tested. I expect some little differences.

The haddock documentation was for my own use only. I don't expect it to be really useful and it is probably full of typos so expect several updates to the package just for that. It is better to look at the test.hs file in the Test folder of the package.

There is a C file in the package. I think I'll replace it with an Haskell implementation in a later release. I have not tested if it builds on windows (I do not have access to a windows box for the 2 following weeks.. I am lucky).

Any suggestion or patch is welcome. Any bug report is very welcome. Any cool example generated with the library is also welcome :-)

You can download the package on Hackage.

10. Examples

You'll find two examples attached to this post. The quasifucs file was sent to me by apfelmus from the Haskell community.

(This post was imported from my old blog. The date is the date of the import. The comments where not imported.)

blog comments powered by Disqus