Completing PDFs with Clojure

This is a quick post about a fantastic little clojure libary called pdfboxing. Among other things, pdfboxing lets you map a map of fields to a PDF document and produce a completed document. For example the following code completes a claim form for the Anthem health insurance:

(ns core
  (:require [pdfboxing.form :as form]))

 {"Total"                                                 "23"
  "Last name"                                             "Doe"
  "Last name_2"                                           "Doe"
  "First name"                                            "John"
  "First name_2"                                          "John"
  "Does the patient have other health insurance coverage" "No"
  "ZIP code"                                              "94342"
  "State"                                                 "CA"
  "City"                                                  "Great City"
  "Street address please include apt no"                  "3 3rd Street Apt 302"
  "Identification no"                                     "ZYUODSJD898"
  "Group no"                                              ""
  "Group no_2"                                            "3938202394"
  "Relation to subscriber"                                "Self"
  "Sex"                                                   "Male"
  "Date of birth MMDDYYYY"                                "12031987"
  "Date of birth MMDDYYYY_2"                              "12031987"
  "Where service rendered"                                "Outpatient"
  "Result of accident"                                    "No"
  "Workers Comp"                                          "No"
  "Job related"                                           "No"
  "Printed name"                                          ""
  "Date MMDDYYYY"                                         "01052020"
  "Home phone no"                                         ""
  "Amount.0"                                              "23"
  "Diagnosis code.0"                                      "112322"
  "Procedure code.0"                                      "202-20202"
  "Tax ID.0"                                              "2212"
  "Date of Service.0"                                     "12202019"})

And it renders like this:

Completed Form

It is beautiful to note how little boilerplate code is needed for accomplishing this task, almost all of the code is essential, almost all of the code is data!

Using this library, you can leverage the full power of programming to complete forms which means you:

  • will make fewer mistakes
  • can easily adapt to changing forms format (just rename the entry but keep the data)
  • can use loops to add multiple entries or even create multiple forms!
  • will not get ink on your hands