This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-01
Channels
- # announcements (20)
- # babashka (3)
- # beginners (30)
- # calva (28)
- # cider (3)
- # circleci (4)
- # clerk (27)
- # clj-kondo (72)
- # cljdoc (15)
- # cljs-dev (1)
- # clojure (85)
- # clojure-europe (37)
- # clojure-nl (1)
- # clojure-norway (13)
- # clojure-spec (7)
- # clojurescript (19)
- # clr (1)
- # conjure (11)
- # datahike (2)
- # datomic (11)
- # emacs (26)
- # events (4)
- # hoplon (35)
- # hyperfiddle (41)
- # jobs (7)
- # lsp (10)
- # nrepl (3)
- # off-topic (57)
- # portal (47)
- # practicalli (1)
- # rdf (3)
- # reitit (21)
- # releases (1)
- # testing (6)
- # tools-build (16)
- # wasm (1)
- # xtdb (16)
I am trying to read a pdf and convert to an image, but I am struggling creating a js/File to pass into my reader. Running into undeclared var blob
(js/console.log (readFileData (new js/File [blob] "test.pdf")))
what is [blob]
? is it declared somewhere?
I have the following code to do the conversion:
(defn readFileData
[file]
(js/Promise.
(fn [resolve reject]
(let [reader (new js/FileReader)]
(set! (.-onload reader) (fn [e] (resolve (.. e -target -result))))
(set! (.-onerror reader) (fn [err] (reject err)))
(js/console.log "Converted")
(.readAsDataURL reader file)))))
(defn convertPDFToImages
[file]
(let [images []
data (<p! (readFileData "test.pdf"))
pdf (<p! (.-promise (.getDocument pdfjs data)))
canvas (.createElement js/document "canvas")
pages (.numPages pdf)]
(loop [i 0]
(if (< i pages)
(let [page (<p! (.getPage pdf (+ i 1)))
viewport (.getViewport page {:scale 1})
context (.getContext canvas "2d")]
(set! (.-height canvas) (.-height viewport))
(set! (.-width canvas) (.-width viewport))
(<p! (.-promise (.render page #js {:canvasContext context, :viewport viewport})))
(conj images (.toDataURL canvas))
(.remove canvas)
(recur (inc i)))
images))))
Which is converted from:
https://stackoverflow.com/questions/61637191/how-to-convert-pdf-to-image-in-reactjs(new js/File [blob] "test.pdf")
this expression expects to have blob
clojurescript var defined somewhere.
this blob should contain the content of your pdf file
Well I am at a loss. What came first the Blob or the file reader hahah. I'll keep searching, thanks for the help
If you're in a browser, the only way to get reference to an external file is via <input type="file" ...>
.
Yeah that is what I am discovering ;( I found a npm package but it is out of date. Basically I want the user to select a local pdf and convert it to an img to display it locally, but right now I am just trying to get the pdf to img conversion working. If I were to select the file using an input, would I be able to pass it into the reader?
Hi guys.
I recently learnt how to generate ClojureScript build report with shadow-cljs
. The build report that is written to an HTML file has an Optimized
column. What does the Optimized
mean?
it is the size of the code that remains after :advanced
optimizations/minification are applied
Thanks.
I included the hook so it generates this report when a release
is run.
:build-hooks [(shadow.cljs.build-report/hook
{:output-to "tmp/report.html"})]
But the issue is that I run this release in a GitHub workflow. How can I preview the generated report in this case?Alright.
Never used it myself, but maybe look into github action artifacts: https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts