                            ))
          ]
     ;; TODO FIX HTML
-
     (fn [out]
       (pdf/pdf (into [pdf-settings [:spacer 4]]
                      (page-template page)) out))))

                                                                 (into [:table {:border false :widths [1 3] :keep-together? false}]
                                                                       (conj  (into [[[:cell {:colspan 2}]]] (for [badge (:badges %)
                                                                                                                   :let [b (badge-info-fn ctx user-id (conj () (:id badge)))
                                                                                                                         content (first (:content (first b)))]]
                                                                                                               (when-not (empty? b)
                                                                                                                 (conj [[:cell {:align :left} (if (ends-with? (:image_file badge) "png") [:image {:align :center :width 75 :height 75}(str data-dir "/" (:image_file badge))] [:image {:align :center :width 75 :height 75 :base64 true} (:qr_code (first b))])]]
                                                                                                                       [:cell
                                                                                                                        [:paragraph.generic
                                                                                                                         [:heading (:name badge)]
                                                                                                                         [:chunk.bold (str (t :badge/Issuedby ul) ": ")] [:chunk (or (:issuer_content_name content) "-")] "\n"
                                                                                                                         (when-not (blank? (str (:issued_on badge)))
                                                                                                                           [:phrase
                                                                                                                            [:chunk.bold (str (t :badge/Issuedon ul)": ")] [:chunk (date-from-unix-time (long (* 1000 (:issued_on badge))) "date")] "\n"])
                                                                                                                         (or (:description badge) "-") "\n"
                                                                                                                         [:spacer 0]
                                                                                                                         [:paragraph {:keep-together true}
                                                                                                                          [:phrase.bold (str (t :badge/Criteria ul)": ")] "\n"
                                                                                                                          [:anchor {:target (:criteria_url badge) :style{:family :times-roman :color [66 100 162]}} (or (:criteria_url badge) "-")] "\n"
                                                                                                                          (when-not (blank? (:criteria_content content))
                                                                                                                            (markdown->clj-pdf {:spacer {:extra-starting-value 0 :allow-extra-line-breaks? false} :paragraph {:keep-together? true} :wrap {:global-wrapper :paragraph}} (or (:criteria_content content) "-")))
                                                                                                                          ]
                                                                                                                         ][:spacer 0]]))))
                                                                              [[:cell {:colspan 2}[:line {:dotted true}]]]))

       ;;     (apply str)
       ))

(defn generate-pdf [ctx page-id user-id header?]
  (let [ badge-info-fn (first (plugin-fun (get-plugins ctx) "pdf" "pdf-generator-helper"))
         page (replace-nils (conj () (page-with-blocks ctx page-id)))
         data-dir (get-in ctx [:config :core :data-dir])
         site-url (get-in ctx [:config :core :site-url])
         plugins (get-plugins ctx)
         user-data (ud/user-information ctx user-id)
         ul (if (blank? (:language user-data)) "en" (:language user-data))
         font-path  (first (mapcat #(get-in ctx [:config % :font] []) plugins))
         header-path (first (mapcat #(get-in ctx [:config % :logo] []) plugins))
         font  {:ttf-name (str site-url font-path)}
