 (defn generate
   "Generate a PDF file"
   [file data]
-  (log/info "A4 width=%f, height=%f" (.. PageSize A4 getWidth) (.. PageSize A4 getHeight))
   (let [page         (if (nil? (data "page"))
-                         { "size" { "width" 210 "height" 295 }}
+                         { "size" { "width" 210 "height" 297 }}
                          (data "page"))
         page-rect    (let [size (page "size")]
                        (if (nil? size)
-                         (. PageSize A4)
-                         (Rectangle. (* 2.83 (size "width")) (* 2.83 (size "height")))))
+                           (. PageSize A4)
+                           (Rectangle. (* 2.83 (size "width")) (* 2.83 (size "height")))))
         page-margins (let [margins (page "margins")]
                        (if (nil? margins)
                            { "left" 20 "right" 20 "top" 20 "bottom" 20 }

  "application/pdf")

(def directions { "h" BaseFont/IDENTITY_H
                  "v"   BaseFont/IDENTITY_V })

(def default-fonts (ref {:hmv  (BaseFont/createFont "HeiseiMin-W3" "UniJIS-UCS2-V" BaseFont/EMBEDDED)
                         :hmh  (BaseFont/createFont "HeiseiMin-W3" "UniJIS-UCS2-H" BaseFont/EMBEDDED)

        ]
    (. document open)
    (let [context-byte (.. writer getDirectContent)
          parent       {:object       document
                        :context-byte context-byte
                        :font         (@default-fonts :hkgh)
                        :font-size    (float 10.0)}]
      (add-objects parent (data "pdf_objects")))
    (. document close)
    (. writer close)))

