A PDF Version of OCaml’s Graphics Module

I’ve just completed a PDF version of the Graphics module from the standard OCaml distribution, based on CamlPDF and following the conventions of Pierre Weis’ Postscript version GraphPS.

The implementation is mostly straightforward, but there are are some complications – some shapes (arcs etc.) need to be approximated from bezier curves sections, since they don’t exist as primitives in PDF (Oddly, circles and arcs are primitive in PostScript).

In common with GraphPS, it doesn’t yet support the bitmapped image parts of the Graphics module, though that would be easy to add.

Here’s a particularly luridly coloured example (source PDF here):

Example GraphPDF Output

GraphPDF will ship with the next release of CamlPDF.

What might be nice for the future would be a single module shipping with OCaml which can be used as the ordinary graphics module would be, and then dump the result to PDF when required.

We’d need to extend the graphics module with the ability to optionally keep a list of all commands executed thus far, but that’s about all. Getting the PDF output into Ocaml would require some license work on CamlPDF, though, so won’t happen yet.

This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *