Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Filling PDF AcroForm with Clojure and iText 7 community edition POF
#!/usr/bin/env boot
; vim: set ft=clojure:
(set-env! :dependencies
'[[com.itextpdf/forms "7.0.2"]])
(import
'[com.itextpdf.forms PdfAcroForm]
'[com.itextpdf.kernel.pdf PdfDocument PdfReader PdfWriter]
'[java.io IOException])
(defn run []
(let [template "Gildi-lanaeydublad.pdf"
filled "Gildi-lanaeydublad-filled.pdf"
pdf-doc (PdfDocument. (PdfReader. template) (PdfWriter. filled))
form (PdfAcroForm/getAcroForm pdf-doc true)]
(.removeXfaForm form)
(.setValue (.getField form "nafn") "Hello")
(.setValue (.getField form "lan 3") "On")
(.close pdf-doc)))
(defn -main [& args]
(println "here")
(run))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment