(lispkit draw web)
(import (lispkit base)
(lispkit draw) ; For using `save-image`
(lispkit draw web) ; For web client functionality
(lispkit thread future)) ; For handling futures
(save-image
"~/Downloads/objecthub.jpeg" ; Filename
(future-get ; Wait for snapshot generation to finish
(web-client-snapshot-url ; Generate snapshot for given URL
(make-web-client 1200) ; Create simple web client with 1200 points width
"http://objecthub.com")) ; URL to snapshot
'jpg) ; Save image as JPEG(import (lispkit base)
(lispkit draw)
(lispkit draw web)
(lispkit thread future))
(define (generate-web-report data-source path)
;; Create web client optimized for documents
(define client (make-web-client 600 '() #f "Report Generator" 1.5))
;; Generate report in HTML form
(define html
(string-append
"<!DOCTYPE html><html><head>"
"<title>Report</title>"
"<style>body { font-family: Georgia, Arial; }"
"h1 { color: #333; padding: 4px; border-bottom: 2px solid #ccc; }"
"table { border-collapse: collapse; width: 100%; }"
"th, td { border: 1px solid #ddd; padding: 8px; }</style>"
"</head><body>"
"<h1>Data Report</h1>"
"<table><tr><th>Item</th><th>Value</th></tr>"
(apply string-append
(map (lambda (item)
(string-append "<tr><td>" (car item) "</td>"
"<td>" (cdr item) "</td></tr>"))
data-source))
"</table></body></html>"))
;; Render and snapshot the report both as bitmap and PDF.
(define img-snapshot
(web-client-snapshot-html client html 'all))
(define pdf-snapshot
(web-client-pdf-snapshot-html client html 'all))
;; Wait for completion and save the snapshots
(save-image
(string-append path ".png")
(future-get img-snapshot)
'png)
(write-binary-file
(string-append path ".pdf")
(future-get pdf-snapshot)))
;; Use the report generator
(define sample-data
'(("Revenue" . "$125,000")
("Expenses" . "$89,500")
("Profit" . "$35,500")
("Growth" . "12.5%")))
(generate-web-report sample-data "~/Downloads/report")Web clients
Crop Modes
Image snapshots
PDF snapshots
Last updated