From ca7bd34b46ef8084ebc38e51347e462592c966d8 Mon Sep 17 00:00:00 2001 From: gered Date: Thu, 17 Sep 2020 14:25:14 -0400 Subject: [PATCH] committing some manual pdf tests. not automated unfortunately :( --- .gitignore | 3 +- project.clj | 37 ++-- test-resources/clojure-logo-120b.png | Bin 0 -> 4021 bytes test-resources/hello-world.html | 28 +++ .../test/pdfdoc_manual_tests.clj | 187 ++++++++++++++++++ 5 files changed, 237 insertions(+), 18 deletions(-) create mode 100644 test-resources/clojure-logo-120b.png create mode 100644 test-resources/hello-world.html create mode 100644 test/clj_htmltopdf/test/pdfdoc_manual_tests.clj diff --git a/.gitignore b/.gitignore index b8f73f5..8c72683 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ pom.xml.asc *.iml *.ipr *.iws -.idea \ No newline at end of file +.idea +/*.pdf diff --git a/project.clj b/project.clj index b935429..9d6b921 100644 --- a/project.clj +++ b/project.clj @@ -1,21 +1,24 @@ (defproject clj-htmltopdf "0.1-alpha8" - :description "Simple Clojure wrapper for Open HTML to PDF" - :url "https://github.com/gered/clj-htmltopdf" - :license {:name "GNU Lesser General Public License v3.0" - :url "https://www.gnu.org/licenses/lgpl.html"} + :description "Simple Clojure wrapper for Open HTML to PDF" + :url "https://github.com/gered/clj-htmltopdf" + :license {:name "GNU Lesser General Public License v3.0" + :url "https://www.gnu.org/licenses/lgpl.html"} - :dependencies [[com.openhtmltopdf/openhtmltopdf-core "1.0.4"] - [com.openhtmltopdf/openhtmltopdf-pdfbox "1.0.4"] - [com.openhtmltopdf/openhtmltopdf-rtl-support "1.0.4"] - [com.openhtmltopdf/openhtmltopdf-svg-support "1.0.4"] - [org.jsoup/jsoup "1.12.1"] - [commons-io/commons-io "2.6"] - [hiccup "1.0.5"]] + :dependencies [[com.openhtmltopdf/openhtmltopdf-core "1.0.4"] + [com.openhtmltopdf/openhtmltopdf-pdfbox "1.0.4"] + [com.openhtmltopdf/openhtmltopdf-rtl-support "1.0.4"] + [com.openhtmltopdf/openhtmltopdf-svg-support "1.0.4"] + [org.jsoup/jsoup "1.12.1"] + [commons-io/commons-io "2.6"] + [hiccup "1.0.5"]] - :profiles {:provided - {:dependencies [[org.clojure/clojure "1.9.0"]]} + :resource-paths ["resources"] - :dev - {:dependencies [[pjstadig/humane-test-output "0.9.0"]] - :injections [(require 'pjstadig.humane-test-output) - (pjstadig.humane-test-output/activate!)]}}) + :profiles {:provided + {:dependencies [[org.clojure/clojure "1.9.0"]]} + + :dev + {:dependencies [[pjstadig/humane-test-output "0.9.0"]] + :resource-paths ["test-resources"] + :injections [(require 'pjstadig.humane-test-output) + (pjstadig.humane-test-output/activate!)]}}) diff --git a/test-resources/clojure-logo-120b.png b/test-resources/clojure-logo-120b.png new file mode 100644 index 0000000000000000000000000000000000000000..56dea4fc2a265e0ed268e81bb4934edcb63a1fc8 GIT binary patch literal 4021 zcmV;m4@&TfP)S4l)cRCwC#U1@Ao*BQOfn3yHl2Akam z+cdbKs2;0CjzGdjN?NrF0otmiQA9$2B(0*RAey#+Qfz*T4m-h)7r?{04v^Nuun;2Do+-g)P{-*&%8NQe+2 zLWBqrB1DJ~Awq-*@$kSI3tu7@i&fDB9!>O7LLU+DsnVo>CnHK914;iL^o~7_<3vM( zvrlM~M`oi(V5#Ll(M}&7I8wsfLxM9y>Wdzss{RBwT=ES(@b#4Fo`;%X&#b+n>Jfv)j^l&mSl2a|;Gh74m()H= z7FSJjkBWe&-9ky;_RtZmquSvc_sCz5_PfLeNveqK#<~)+yslVP*--PEY=%}&hRMYm zyT{8qNtxjHI{I8&Ak_01&>91f7L8^ea^PIb^;)GgO|YI0^Tv!+p&(XHB5CKFduBA zByY?Mf+@MHy*QT(gg^P@CEM__p=KW-wYe*&3HI7%I*B0l2-W6tY@210>w{<)DzNxo zdqm`d*oTo^g(Yc^m&Ubeq6_HI@u9$!4RS%U z;B#9Gog4#leZA&<2iE?#|MpoR>%T;dY{jcKAy}%2Fcy%gaM?E9ufI?!sw<=EennOY z_SAbi7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clj b/test/clj_htmltopdf/test/pdfdoc_manual_tests.clj new file mode 100644 index 0000000..6017a0e --- /dev/null +++ b/test/clj_htmltopdf/test/pdfdoc_manual_tests.clj @@ -0,0 +1,187 @@ +(ns clj-htmltopdf.test.pdfdoc-manual-tests + (:require + [clojure.java.io :as io] + [clj-htmltopdf.core :refer [->pdf embed-image]])) + +; this is a kind of "poor mans" set of tests. it is a bit difficult to put together a set of fully automated +; tests for PDF document generation, so for now this will have to suffice. +; +; how to use: manually run each one in a REPL, verify the PDF looks as expected. yup, very ghetto! :'( + + +(comment + (let [filename "test-basic.pdf"] + (println "\n **** " filename " **** \n") + (->pdf + [:div + [:h1 "HTML to PDF"] + [:p "Glorious!"]] + filename))) + +(comment + (let [filename "test-images.pdf"] + (println "\n **** " filename " **** \n") + (->pdf + [:div + [:h1 "Using Images"] + [:div "Local image file" [:img {:src "clojure-logo-120b.png"}]] + [:div "Remote image via URL" [:img {:src "https://clojure.org/images/clojure-logo-120b.png"}]] + [:div "Embedded image via CSS data" [:img {:src (embed-image (io/resource "clojure-logo-120b.png"))}]]] + filename))) + +(comment + (let [filename "test-object-drawing.pdf"] + (println "\n **** " filename " **** \n") + (->pdf + [:div + [:h2 "Object Drawing Test"] + [:object {:id "the-object" :style "width: 400px; height: 300px;"}] + [:p "Text after the object"]] + filename + {:objects + {:by-id + {"the-object" + (fn [object-element-attrs ^java.awt.Graphics2D g] + (.setColor g java.awt.Color/RED) + (.drawRect g 50 50 200 200) + (.setColor g java.awt.Color/BLUE) + (.drawRect g 75 75 300 200))}}}))) + +(comment + (let [filename "test-svg.pdf"] + (println "\n **** " filename " **** \n") + (->pdf + [:div + [:h2 "SVG test"] + [:svg {:xmlns "http://www.w3.org/2000/svg" :version "1.1"} + [:rect {:x 25 :y 25 :width 200 :height 200 :fill "lime" :stroke-width 4 :stroke "pink"}] + [:circle {:cx 125 :cy 125 :r 75 :fill "orange"}] + [:polyline {:points "50,150 50,200 200,200 200,100" :stroke "red" :stroke-width 4 :fill "none"}] + [:line {:x1 50 :y1 50 :x2 200 :y2 200 :stroke "blue" :stroke-width 4}]] + [:hr] + [:svg {:xmlns "http://www.w3.org/2000/svg" :width 100 :height 100} + [:circle {:cx 50 :cy 50 :r 40 :stroke "green" :stroke-width 4 :fill "yellow"}]] + [:hr] + [:svg {:xmlns "http://www.w3.org/2000/svg" :width 300 :height 200} + [:rect {:width "100%" :height "100%" :fill "red"}] + [:circle {:cx 150 :cy 100 :r 80 :fill "green"}] + [:text {:x 150 :y 125 :font-size 60 :text-anchor "middle" :fill "white"} "SVG"]]] + filename))) + +(comment + (let [filename "test-custom-styles.pdf"] + (println "\n **** " filename " **** \n") + (->pdf + '([:head + [:style {:type "text/css"} + ".custom { font-family: monospace; color: #ff0000; }"]] + [:body + [:p.custom "this should be custom styled"] + [:p "this should be normally styled. and the following table should be styled as per htmltopdf-base.css still"] + [:table {:border 1} + [:thead + [:tr + [:th "Column A"] + [:th "Column B"] + [:th "Column C"]]] + [:tbody + [:tr + [:td "1"] + [:td "2"] + [:td "3"]] + [:tr + [:td "A"] + [:td "B"] + [:td "C"]] + [:tr + [:td "i"] + [:td "ii"] + [:td "iii"]]]]]) + filename + {:debug {:display-html? true + :display-options? true}}))) + +(comment + (let [filename "test-report.pdf"] + (println "\n **** " filename " **** \n") + (->pdf + [:div + [:div#margin-box-top-left "this is my custom header"] + [:div#margin-box-bottom-center + [:table + [:tr + [:td "footer column A"] + [:td "footer column B"] + [:td "footer column C"]]]] + [:h1 "My PDF Title"] + [:p "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."] + [:p "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."] + [:h3 "Sub Title"] + [:p "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."] + [:pre "(defn say-hello! [name]\n (println \"Hello,\" name))"] + [:p.page-break-after "Going onto page 2 next ... !"] + [:table + [:thead + [:tr + [:th {:width "6%"} "#"] + [:th {:width "32%"} "Name"] + [:th {:width "32%"} "Username"] + [:th {:width "32%"} "Role"]]] + [:tbody + [:tr + [:th "1"] + [:th "Gered"] + [:th "gered"] + [:th "Developer"]] + [:tr + [:th "2"] + [:th "Bob"] + [:th "bob"] + [:th "Sales Associate"]] + [:tr + [:th "3"] + [:th "Sue"] + [:th "sue"] + [:th "Designer"]] + [:tr + [:th "4"] + [:th "Joe"] + [:th "joe"] + [:th "Manager"]]]] + [:ul + [:li "first item"] + [:li "second item"] + [:li "third item"]] + [:ol + [:li "more items"] + [:li "for you"] + [:li "to see!"]] + [:img {:src "https://clojure.org/images/clojure-logo-120b.png"}]] + filename + {:doc {:title "My Awesome PDF" + :author "Gered" + :subject "Only Testing" + :keywords "clojure,html,to,pdf"} + :page {:margin "1.0in" + :size :letter + :orientation :portrait + :margin-box {:top-left {:element "margin-box-top-left"} + :top-right {:paging [:page " of " :pages]} + :bottom-center {:element "margin-box-bottom-center"} + :bottom-right-corner {:text "corner!"}}} + :styles {:font-size "12pt" + :color "#000"} + :debug {:display-html? true + :display-options? true}}))) + + +(comment + (let [filename "test-completely-custom.pdf"] + (println "\n **** " filename " **** \n") + (->pdf + (io/resource "hello-world.html") + filename + {:styles nil + :page nil + :debug {:display-html? true + :display-options? true}})))