Skip to content

spaceninja/eleventy-pdf

Repository files navigation

Eleventy PDF

This repo is an example of how to have a static website that is automatically converted into a PDF using DocRaptor. We're using Eleventy, but you could use any static site generator, including hand-maintained HTML files. We're using DocRaptor, which is a friendly and affordable API build on top of the Prince PDF service, but you could use other HTML-to-PDF services, including WeasyPrint or the Adobe PDF Services API.

How This Works

The repo will build a standard static site — in this case, a chapter-navigable version of the Sherlock Holmes story, A Study In Scarlet — with some basic CSS.

In addition, it will output a single-page version of the entire book. This HTML file loads the same CSS as the main site, it just keeps everything in a single file, which is needed so DocRaptor can add page numbers.

We then have a node script that will load the contents of the single-page version, inline all the CSS and images, and then submit the resulting HTML to the DocRaptor API, which returns a PDF that we save to the dist directory.

For more information, check out build-pdf.mjs and this blog post (coming soon).

You can also view the demo site and the demo pdf.