The Gilt technology organization. We make work.

Create PDFs from Scala Using HTML, CSS and JavaScript

Gilt Senior Software Engineer Federico Feroldi just released sPDF (pronounced speedy-f): a Scala library that makes it super-easy to create complex PDFs from HTML, CSS and JavaScript. On the backend sPDF uses wkhtmltopdf, which renders HTML using Webkit.

In creating sPDF, Federico was heavily inspired by Ruby’s PdfKit gem, which also uses HTML, CSS and wkhtmlopdf to create PDFs. 

sPDF’s main features include:

  • full support of wkhtmltopdf extended parameters (see the source of the PdfConfig trait)
  • can read HTML from several sources:,,, scala.xml.Elem, and String
  • can write PDFs to File and OutputStream

The source HTML can reference to images and stylesheet files as long as the URLs point to the absolute path of the source file. It’s also possible to embed JavaScript code in the pages: wkhtmltopdf will wait for the document-ready event before generating the PDF.

This is Federico’s second open source Scala library. His other recent project, Lucene Sugar, provides a more concise syntax for the Lucene API in the Scala language. Let him know what you think of both projects by contacting him via his GitHub page.

sPDF 1 wkhtmltopdf 1 CSS 12 JavaScript 18 open source 64 Scala 79 Federico Feroldi 1 PDFs 1 libraries 3 HTML 8 Cloudify 1 PDFkit 1