Web Development with Clojure by Dmitri Sotnikov
Author:Dmitri Sotnikov
Language: eng
Format: epub
Tags: Pragmatic Bookshelf
Publisher: Pragmatic Bookshelf
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:
â (pdf
â [{: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
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.
API Testing and Development with Postman by Dave Westerveld(3605)
Learning C# by Developing Games with Unity 2020 by Harrison Ferrone(2603)
Software Architecture for Busy Developers by Stéphane Eyskens(2308)
2021 Beginners Guide to Python Programming Language: A Crash Course to Mastering Python in One Hour by Elmer Gary & Elmer Gary(1884)
Machine Learning for Algorithmic Trading by Stefan Jansen(1628)
Hands-On ROS for Robotics Programming by Bernardo Ronquillo Japón(1572)
Delphi GUI Programming with FireMonkey by Andrea Magni(1457)
Game Development Projects with Unreal Engine by Hammad Fozi & Goncalo Marques & David Pereira & Devin Sherry(1401)
Cloud Native with Kubernetes by Alexander Raul(1374)
Datadog Cloud Monitoring Quick Start Guide by Thomas Kurian Theakanath(1346)
Software Architecture Patterns for Serverless Systems by John Gilbert(1338)
Practical Node-RED Programming by Taiji Hagino(1336)
Automate It with Zapier by Kelly Goss(1318)
Practical System Programming for Rust Developers by Prabhu Eshwarla(1312)
Delphi Programming Projects by William Duarte(1296)
Mastering React Test-Driven Development by Daniel Irvine(1288)
Developing Multi-Platform Apps with Visual Studio Code by Ovais Mehboob Ahmed Khan & Khusro Habib & Chris Dias(1253)
Ghidra Software Reverse Engineering for Beginners by A. P. David(1243)
Learn Spring for Android Application Development by S. M. Mohi Us Sunnat(1235)
