Skip to content

Commit

Permalink
added multi-column element
Browse files Browse the repository at this point in the history
  • Loading branch information
yogthos committed Dec 9, 2016
1 parent 0e3490b commit b54c272
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
33 changes: 32 additions & 1 deletion README.md
Expand Up @@ -269,6 +269,7 @@ Use the CSS-like shortcut for applying classes to elements (e.g. `[:paragraph.fo
[Image](#image),
[Line](#line),
[List](#list),
[Multi-Column](#multi-column),
[Pagebreak](#pagebreak),
[Paragraph](#paragraph),
[Phrase](#phrase),
Expand Down Expand Up @@ -731,6 +732,36 @@ content:
"yet another item"]
```

#### Multi-Column

Creates a multi-column text element.

tag :multi-column

optional metadata:

* :top - number
* :height - number
* :columns - number of columns (required)

content:"
A string of text that will be split into columns.
```clojure
[:multi-column
{:columns 3}
"This text will be split into three columns"]
[:multi-column
{:top 10 :columns 3}
"This text will be split into three columns"]
[:multi-column
{:top 10 :height 100 :columns 3}
"This text will be split into three columns"]
```
#### Pagebreak
tag :pagebreak
Expand Down Expand Up @@ -970,7 +1001,7 @@ metadata:
[[:cell {:colspan 2} "Foo"] "Bar"]
[[:cell "foo1" " " "foo2"] "bar1" "baz1"]
["foo2" "bar2" "baz2"]]
[:table
{:header ["A" "B" [:cell {:colspan 2 :align :center} "Cell"]]}
["1a" "1b" "1c" "1d"]
Expand Down
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject clj-pdf "2.2.10"
(defproject clj-pdf "2.2.11"
:description "PDF generation library"
:url "https://github.com/yogthos/clj-pdf"

Expand Down
21 changes: 20 additions & 1 deletion src/clj/clj_pdf/core.clj
Expand Up @@ -36,7 +36,7 @@
Table
ZapfDingbatsList
ZapfDingbatsNumberList]
[cljpdf.text.pdf BaseFont PdfReader PdfStamper PdfWriter PdfPCell PdfPTable]
[cljpdf.text.pdf BaseFont MultiColumnText PdfReader PdfStamper PdfWriter PdfPCell PdfPTable]
[java.io PushbackReader InputStream InputStreamReader OutputStream FileOutputStream ByteArrayOutputStream]))

(declare ^:dynamic *cache*)
Expand Down Expand Up @@ -689,6 +689,24 @@
item)
(throw (Exception. (str "reference tag not found: " reference-id))))))

(defn- multi-column [{:keys [left-margin right-margin page-width gutter-width top height columns] :as meta} content]
(let [ml-text (cond
(and top height)
(MultiColumnText. (float top) (float height))
height
(MultiColumnText. (float height))
:else
(MultiColumnText. MultiColumnText/AUTOMATIC))]
(.addRegularColumns ml-text
(float left-margin)
(float (- page-width right-margin))
(float (or gutter-width 10))
(int columns))
(.addElement ml-text (make-section meta (if (string? content)
[:phrase content]
content)))
ml-text))

(defn- spacer
([_] (make-section [:paragraph {:leading 12} "\n"]))
([_ height]
Expand Down Expand Up @@ -749,6 +767,7 @@
:svg svg-element
:line line
:list li
:multi-column multi-column
:paragraph paragraph
:phrase phrase
:reference reference
Expand Down

0 comments on commit b54c272

Please sign in to comment.