Jekyll PDF
Dynamically generate PDFs from Jekyll pages, posts & documents.
Using Jekyll Assets with Jekyll
Add gem "jekyll-pdf" to your Gemfile and add jekyll-pdf to your _config.yml like the following:
gems:
- jekyll-pdf
Now add the following to any page's or document's front-matter, that you'd like to create a PDF version of.
pdf: true
To activate Jekyll PDF for multiple pages or entire collections you can use Jekyll's front-matter defaults.
Configuration
Jekyll PDF uses wkhtmltopdf to generate the PDFs. For a full list of configuration parameters it supports see http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
pdf:
cache: false | directory | default: .asset-cache
page_size: A4, Letter, etc. | default: A4
layout: layout | default: pdf
PDF Layouts
Jekyll PDF will check for your current layout suffixed with _pdf e.g. if you're using a layout called post, it will look for _layouts/post_pdf.html, falling back to your default PDF layout (usually _layouts/pdf.html).
To override this add the pdf_layout variable to your page's YAML front-matter. For example:
pdf_layout: my_custom_pdf_layout
Partials - Headers, Footers & Covers
We'll automatically look for all partials in _includes directory, e.g. header_html: pdf_header.html will tell Jekyll PDF use _includes/pdf_header.html. Please note that wkhtmltopdf requires all partials to be valid HTML documents (including DOCTYPE).
Cache Folder
If Jekyll Assets is installed, Jekyll PDF will automatically use the same cache folder as Jekyll Assets unless specified otherwise.
Troubleshooting
Resources aren't included in the PDF
If your Images, CSS, or JavaScript aren't displaying in the PDF, this is most likely due to the fact that wkhtmltopdf doesn't know where to look. Try prefixing your asset URLs with file://{{ site.dest }}. For asset URLs in CSS files we recommend creating a separate CSS file overriding the URLs will the mentioned prefix.
To Do
- Support layouts in partials
- Default PDF layout file in Gem
- Write tests