Skip to content

Instantly share code, notes, and snippets.

@abcdw
Created August 6, 2019 08:35
Show Gist options
  • Save abcdw/156bdf6f586e509ea15f0318293ba353 to your computer and use it in GitHub Desktop.
Save abcdw/156bdf6f586e509ea15f0318293ba353 to your computer and use it in GitHub Desktop.
(ns rk-server.data-sending.pdf
(:require [unifn.core :as u]
[clj-htmltopdf.core :as htmltopdf]
[cheshire.core :as json]
[rk-server.email.core :as email]
[rk-server.data-sending.db :as db]
[rk-server.utils :as ut]
[rk-server.data-request :as data-request]
[rk-server.data-sending.crud :as crud]
[rk-server.data-sending.html :as html]
[rk-server.data-sending.common :as common]
[clojure.string :as str]
[rk-server.legal-documents :as legal-documents])
(:import [java.io ByteArrayOutputStream ByteArrayInputStream InputStream]
[java.util Base64]
[net.interfax.rest.client.impl DefaultInterFAXClient]
[org.apache.pdfbox.pdmodel PDDocument PDPage PDPageContentStream PDPageContentStream$AppendMode]))
(defn send-data-pdf [fax-number arg real-fax]
(binding [html/*manifest* arg]
(let [os (ByteArrayOutputStream.)
os (htmltopdf/->pdf (html/build-document (::data arg)
(::user arg)
(legal-documents/disclosure :server)
real-fax
nil)
os common/pdf-options)
is (ByteArrayInputStream. (.toByteArray os))
fax (DefaultInterFAXClient.)
response (.sendFax fax fax-number
(into-array InputStream [is])
(into-array String ["application/pdf"]))]
{:state {:status-code (.getStatusCode response)}
:body (json/parse-string (.getResponseBody response))})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment