Thursday, August 9, 2012

clj-pdf, Clojure PDF library and instant-pdf, a RESTful PDF generation service

By Vasudev Ram


[ UPDATE: I emailed the author of clj-pdf and instant-pdf, and he told me two things: 1) the instant-pdf bug mentioned below seems to be due to a Clojure JSON library (see the comments on this post), and does not occur when clj-pdf is used directly, and 2) clj-pdf uses the iText PDF library for generating PDF. ]

Saw this via proggit (programming.reddit.com):

clj-pdf is a Clojure library for PDF generation.

instant-pdf is a RESTful web service for PDF generation, built using clj-pdf. It supports JSON for markup. Interesting approach.
It has a fairly large JSON syntax for many elements of PDF, like metadata, text, paragraphs, chapters, colors, tables, etc.

I tried it out a bit. What I tried mostly worked, except for one issue - pasting a DOS directory listing into the text box (for the content section), resulted in PDF output that contained the string "null" instead of backslashes, e.g. for a path like C:\abc\def\some-file.

clj-pdf uses JFreeChart.

P.S. I liked this blog post: WHY ALL THE PARENS, by yogthos, the author of clj-pdf.

- Vasudev Ram - Dancing Bison Enterprises

2 comments:

Unknown said...

As a note the null appears to be a byproduct of the clojure.data.json library I'm using to parse JSON:


(read-json "\"C:\\abc\\def\\some-file\"")

outputs:

"C:nullbcnullefnullome-file"


If the above string is passed to clj-pdf directly then it will be handled correctly.

Vasudev Ram said...

Thought so, as I said in my email to you just now. From your check, it looks like the json library is not handling backslashes correctly. Thanks for the clarification.