Compare commits

...

4 Commits

Author SHA1 Message Date
Alejandro Alonso
86cb6b6f51 WIP 2026-02-04 14:16:26 +01:00
Alejandro Alonso
f3e0c2409e WIP 2026-02-04 14:11:12 +01:00
Alejandro Alonso
8584e070f9 WIP 2026-02-04 14:06:03 +01:00
Alejandro Alonso
49ea9a30a9 🐛 Fix pdf export 2026-02-04 13:58:03 +01:00

View File

@@ -38,6 +38,26 @@
(assoc :path "/render.html")
(assoc :query (u/map->query-string params)))))
(sync-page-size! [dom]
(bw/eval! dom
(fn [elem]
(let [rect (.getBoundingClientRect ^js elem)
width (js/Math.max (or (some-> (.getAttribute ^js elem "width") js/parseFloat) 0)
(.-width rect))
height (js/Math.max (or (some-> (.getAttribute ^js elem "height") js/parseFloat) 0)
(.-height rect))
width-px (str width "px")
height-px (str height "px")
style-node (or (.getElementById js/document "penpot-pdf-page-size")
(let [node (.createElement js/document "style")]
(set! (.-id node) "penpot-pdf-page-size")
(.appendChild (.-head js/document) node)
node))]
(set! (.-textContent style-node)
(str "@page { size: " width-px " " height-px "; margin: 0; }\n"
"html, body, #app { margin: 0; padding: 0;"
"width: " width-px "; height: " height-px "; }"))))))
(render-object [page base-uri {:keys [id] :as object}]
(p/let [uri (prepare-uri base-uri id)
path (sh/tempfile :prefix "penpot.tmp.pdf." :suffix (mime/get-extension type))]
@@ -45,6 +65,7 @@
(bw/nav! page uri)
(p/let [dom (bw/select page (dm/str "#screenshot-" id))]
(bw/wait-for dom)
(sync-page-size! dom)
(bw/screenshot dom {:full-page? true})
(bw/sleep page 2000) ; the good old fix with sleep
(bw/pdf page {:path path})