Created
June 2, 2023 01:45
-
-
Save jamesdavidson/51e6730656b168f46362c1bf9832fbea to your computer and use it in GitHub Desktop.
Clojure snippet for creating PDF where each page is from a PNG image file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; org.clojure/clojure {:mvn/version "1.11.1"} | |
;; com.github.librepdf/openpdf {:mvn/version "1.3.30"} | |
(import 'com.lowagie.text.Document) | |
(import 'com.lowagie.text.Image) | |
(import 'com.lowagie.text.PageSize) | |
(import 'com.lowagie.text.pdf.PdfWriter) | |
(def doc (new Document)) | |
(def os (io/output-stream "output.pdf")) | |
(PdfWriter/getInstance doc os) | |
(def img-is (io/input-stream "../Downloads/screenshot-7.png")) | |
(def img-baos (new java.io.ByteArrayOutputStream)) | |
(io/copy img-is img-baos) | |
(def img (Image/getInstance (.toByteArray img-baos))) | |
(.setPageSize doc img) | |
(.newPage doc) | |
(.setAbsolutePosition img 0 0) | |
(.open doc) | |
(.add doc img) | |
(.close doc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment