postelrich
postelrich

Reputation: 3496

clj-pdf: Error adding image in a table

I'm using the clj-pdf library for Clojure to create pdf that contain charts. I'm making the charts using the Incanter library and converting the images to byte arrays. Then I'm attempting to use clj-pdf to make a pdf that has 4 charts, one in each corner. When I do this I get an error IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Keyword clojure.lang.RT.seqFrom (RT.java:505)
I can successfully add the images outside of a table but the formatting sucks, one image per line. Anyone how to fix this?

Heres the line of code I'm trying:

(pdf [{} [:table {} [:cell [:image {} plot1-bytearr]
         [:image {} plot2-bytearr]]]] "test.pdf")

EDIT
Link to trace: http://pastebin.com/b7DEnjXY
Link to workable (hopefully) example: http://pastebin.com/fPvjFFbi

Upvotes: 2

Views: 280

Answers (1)

Leon Grapenthin
Leon Grapenthin

Reputation: 9266

A :table needs to be specified in rows, e.g.

(pdf [{} [:table row1 
                 row2
                 row3]] 
     "test.pdf")

Rows need to be sequences.

(pdf [{} [:table ["11" "12" "13"]
                 ["21" "22" "23"]]] "test.pdf")

You have placed two images in one cell, but doing

(pdf [{} [:table [[:cell "11" "12" "13"]]
                 ["21" "22" "23"]]] "test.pdf")

would omit "12" and "13" and create a table with 11, 21 and 22 in the first row and 23 as the first cell in the second row. I don't think this usage of :cell is supported. If you wanted to use multiple cells in one cell I would create another :table vector inside the :cell vector which is supported.

Based on your example the solution is

(pdf [{} [:table [[:image plot1-bytearr][:image plot2-bytearr]]]]
     "test.pdf")

Please note the extra brackets around the vector of :images. Clj-pdf tries to read your :cell keyword as a sequence containing a cell for :table, hence the exception telling you that it's expecting a sequence.

  • This won't give you 4 charts. Since you have only provided two, I guess this solves your problem.

Upvotes: 2

Related Questions