Skip to content

Instantly share code, notes, and snippets.

@rgm
Last active November 9, 2020 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgm/b3fb7c231ca41aad871eaf6115d7699f to your computer and use it in GitHub Desktop.
Save rgm/b3fb7c231ca41aad871eaf6115d7699f to your computer and use it in GitHub Desktop.
(require
'[clj-chrome-devtools.core :as chrome]
'[clj-chrome-devtools.commands.page :as page])
(defn b64-decode
"https://stackoverflow.com/a/39188819/53790"
[to-decode]
(String. (.decode (Base64/getDecoder) to-decode)))
(def c (chrome/connect "localhost" 9222))
(page/navigate c {:url "https://github.com"})
(let [response (page/print-to-pdf c {:page-ranges "1-2"})
pdf-data (b64-decode (:data response))]
(spit "test.pdf" pdf-data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment