-
-
Save mattdeboard/79bad31d2769e9f44639 to your computer and use it in GitHub Desktop.
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
(defn- copyright | |
"Stamp a single-page PDF with a copyright statement." | |
[^PdfStamper s ^Integer i ^String watermark ^Rectangle crop ^PdfReader reader hex-string] | |
(let [oc (itext/over-content s i) | |
bgcolor (new BaseColor 255 255 255) | |
font (. BaseFont createFont | |
(. BaseFont HELVETICA) | |
(. BaseFont WINANSI) | |
(. BaseFont EMBEDDED)) | |
fontcolor (new BaseColor 0 0 0) | |
font-padding (float 4) | |
font-size (float 9) | |
text-angle (float 0) | |
rect-height (+ font-size font-padding) | |
media-box (let [pageSize (. reader getPageSize i)] | |
(if (and crop (or (< (. crop getWidth) | |
(. pageSize getWidth)) | |
(< (. crop getHeight) | |
(. pageSize getHeight)))) | |
crop | |
pageSize)) | |
top (. media-box getTop) | |
left (. media-box getLeft) | |
;; iText uses integer values to represent alignment: | |
;; 0 - ALIGN_LEFT | |
;; 1 - ALIGN_CENTER | |
;; 2 - ALIGN_RIGHT | |
align (. PdfContentByte ALIGN_LEFT)] | |
;; Draw our bounding box in which our copyright will be stamped | |
(. oc setColorFill bgcolor) | |
(. oc moveTo (+ left rect-height) top) | |
(. oc lineTo left top) | |
(. oc lineTo left (- top rect-height)) | |
(. oc lineTo (+ left rect-height) top) | |
(. oc fill) | |
;; Drop our watermark on top of the rectangle we just created | |
(. oc beginText) | |
(. oc setColorFill fontcolor) | |
(. oc setFontAndSize font font-size) | |
(. oc showTextAligned | |
align watermark (+ left (/ font-padding 2)) (- top font-size) text-angle) | |
(. oc endText))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment