Web Development with Clojure: Build Bulletproof Web Apps with Less Code by Dmitri Sotnikov
Author:Dmitri Sotnikov [Sotnikov, Dmitri]
Language: eng
Format: azw3, pdf
Tags: Pragmatic Bookshelf
Publisher: Pragmatic Bookshelf
Published: 2016-07-14T04:00:00+00:00
Generating the Reports
The clj-pdf library uses syntax similar to Hiccup’s to define the elements in the document. The document itself is represented by a vector. The document vector must contain a map representing the metadata as its first element. The metadata is followed by one or more elements representing the document’s content.
Let’s create a namespace called reporting-example.reports and look at a few examples of creating PDF documents. We’ll use the pdf function to create the reports and the template macro to format the input data. We’ll also reference the reporting-example.db.core namespace so that we can call the read-employees function later on.
reporting-example/src/clj/reporting_example/reports.clj
(ns reporting-example.reports
(:require [reporting-example.db.core :as db]
[clj-pdf.core :refer [pdf template]]))
The pdf function accepts two arguments. The first can be either a vector representing the document or an input stream from which the elements are read. The second can either be a string representing the output file name or an output stream.
Let’s generate our first PDF by running the following code in the reporting-example.reports namespace:
[{:header "Wow, that was easy"}
[:list
[:chunk {:style :bold} "a bold item"]
"another item"
"yet another item"]
[:paragraph "I'm a paragraph!"]]
"doc.pdf")
As you can see, the report consists of vectors, each starting with a keyword identifying the type of element, followed by the metadata and the content. In the preceding report we have a list that contains three rows, followed by a paragraph. The PDF will be written to a file called doc.pdf in our project’s root. The contents of the file should look like the following figure:
Download
Web Development with Clojure: Build Bulletproof Web Apps with Less Code by Dmitri Sotnikov.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6532)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Kotlin in Action by Dmitry Jemerov(5062)
Odoo 15 Development Essentials - Fifth Edition by Daniel Reis & Greg Mader(3338)
Odoo 15 Development Essentials by Daniel Reis(2814)
React Native - Building Mobile Apps with JavaScript by Novick Vladimir(2529)
Learning Angular - Second Edition by Christoffer Noring(2358)
Pride and Prejudice by Jane Austen(2349)
Mobile Forensics Cookbook by Igor Mikhaylov(2017)
Computers For Seniors For Dummies by Nancy C. Muir(1995)
Bulletproof Android: Practical Advice for Building Secure Apps (Developer's Library) by Godfrey Nolan(1872)
Android Development with Kotlin by Marcin Moskala & Igor Wojda(1797)
Building Android UIs with Custom Views by Raimon Ràfols Montané(1789)
1936941139 (N) by Bob Rosenthal(1731)
Building Progressive Web Apps: Bringing the Power of Native to the Browser by Ater Tal(1725)
Hands-On Internet of Things with MQTT by Tim Pulver(1706)
Android App Development by Franceschi Hervé J.;(1702)
Ember.js in Action by Joachim Haagen Skeie(1689)
Hands-On Design Patterns with React Native by Mateusz Grzesiukiewicz(1656)
