Giter Club home page Giter Club logo

jekyll-pdf's Introduction

Jekyll PDF

Dynamically generate PDFs from Jekyll pages, posts & documents.

Build Status Dependency Status

Usage

Add gem "jekyll-pdf" to your Gemfile and run bundle, then add jekyll-pdf to your _config.yml like so:

gems:
  - jekyll-pdf

Now add pdf: true to any page's or document's front-matter, that you'd like to create a PDF version of.

To activate Jekyll PDF for multiple pages or entire collections you can use Jekyll's front-matter defaults. The following example will create PDFs for each post in your blog.

defaults:
  -
    scope:
      path: ""
      type: "posts"
    values:
      pdf: true

Link to the PDF using the {{ page.pdf_url }} liquid variable.

Configuration

Jekyll PDF supports any configuration parameters wkhtmltopdf does. 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

All configuration parameters (with exception of cache) can be overridden from your page's or it's PDF layout's front-matter.

Cache Folder

If Jekyll Assets is installed, Jekyll PDF will automatically use the same cache folder as Jekyll Assets (unless specified otherwise).

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 behaviour, add the pdf_layout variable to your page's YAML front-matter. For example:

pdf_layout: my_custom_pdf_layout

Partials (Header, Footer & Cover Page)

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 for example:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css">
</head>
<body>
  Page {{ page.pdf.page }} of {{ page.pdf.topage }}
</body>
</html>

Supported header & footer variables

Liquid Description
{{ page.pdf.page }} Replaced by the number of the pages currently being printed
{{ page.pdf.topage }} Replaced by the number of the last page to be printed
{{ page.pdf.section }} Replaced by the content of the current h1 tag
{{ page.pdf.subsection }} Replaced by the content of the current h2 tag
{{ page.pdf.subsubsection }} Replaced by the content of the current h3 tag

Troubleshooting

Images aren't displaying in the PDF

If your images 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 image URLs with file://{{ site.dest }}.
For asset URLs in CSS files we recommend creating a separate CSS file overriding the URLs with the prefix mentioned above.

Copyright

© 2016 Adam Bouqdib - http://abemedia.co.uk

jekyll-pdf's People

Contributors

abemedia avatar tynn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jekyll-pdf's Issues

Please add additional explanation

The configuration is explained (Gemfile and _config.yml modifications) but not how to actually cause the PDFs to be generated. Does it happen at jekyll build time? Or when the site is served? Where is the file stored? I have made the specified changes, but cannot find any sign that a PDF has been generated. Thank you.

Error when building the website [undefined class/module Digest::Base (ArgumentError)]

I get this error executing bundle exec jekyll build.

/var/lib/gems/2.3.0/gems/sass-3.5.5/lib/sass/engine.rb:2:in `require': undefined class/module Digest::Base (ArgumentError)
	from /var/lib/gems/2.3.0/gems/sass-3.5.5/lib/sass/engine.rb:2:in `<top (required)>'
	from /var/lib/gems/2.3.0/gems/sass-3.5.5/lib/sass.rb:99:in `require'
	from /var/lib/gems/2.3.0/gems/sass-3.5.5/lib/sass.rb:99:in `<top (required)>'
	from /var/lib/gems/2.3.0/gems/jekyll-sass-converter-1.5.1/lib/jekyll/converters/scss.rb:3:in `require'
	from /var/lib/gems/2.3.0/gems/jekyll-sass-converter-1.5.1/lib/jekyll/converters/scss.rb:3:in `<top (required)>'
	from /var/lib/gems/2.3.0/gems/jekyll-sass-converter-1.5.1/lib/jekyll-sass-converter.rb:4:in `require'
	from /var/lib/gems/2.3.0/gems/jekyll-sass-converter-1.5.1/lib/jekyll-sass-converter.rb:4:in `<top (required)>'
	from /var/lib/gems/2.3.0/gems/jekyll-3.7.0/lib/jekyll.rb:198:in `require'
	from /var/lib/gems/2.3.0/gems/jekyll-3.7.0/lib/jekyll.rb:198:in `<top (required)>'
	from /var/lib/gems/2.3.0/gems/jekyll-3.7.0/exe/jekyll:8:in `require'
	from /var/lib/gems/2.3.0/gems/jekyll-3.7.0/exe/jekyll:8:in `<top (required)>'
	from /usr/local/bin/jekyll:23:in `load'
	from /usr/local/bin/jekyll:23:in `<main>'
part of my Gemfile.lock: 
GEM
  remote: https://rubygems.org/
  specs:
    addressable (2.5.2)
      public_suffix (>= 2.0.2, < 4.0)
    bibtex-ruby (4.4.5)
      latex-decode (~> 0.0)
    citeproc (1.0.8)
      namae (~> 1.0)
    citeproc-ruby (1.1.8)
      citeproc (>= 1.0.4, < 2.0)
      csl (~> 1.4)
    colorator (1.1.0)
    concurrent-ruby (1.0.5)
    csl (1.5.0)
      namae (~> 1.0)
    csl-styles (1.0.1.8)
      csl (~> 1.0)
    digest (0.0.1)
    em-websocket (0.5.1)
      eventmachine (>= 0.12.9)
      http_parser.rb (~> 0.6.0)
    eventmachine (1.2.5)
    ffi (1.9.18)
    forwardable-extended (2.6.0)
    http_parser.rb (0.6.0)
    i18n (0.9.3)
      concurrent-ruby (~> 1.0)
    jekyll (3.7.0)
      addressable (~> 2.4)
      colorator (~> 1.0)
      em-websocket (~> 0.5)
      i18n (~> 0.7)
      jekyll-sass-converter (~> 1.0)
      jekyll-watch (~> 2.0)
      kramdown (~> 1.14)
      liquid (~> 4.0)
      mercenary (~> 0.3.3)
      pathutil (~> 0.9)
      rouge (>= 1.7, < 4)
      safe_yaml (~> 1.0)
    jekyll-feed (0.9.2)
      jekyll (~> 3.3)
    jekyll-pdf (0.1.7)
      digest (~> 0)
      jekyll (~> 3.1, >= 2.0)
      pdfkit (~> 0.8)
      wkhtmltopdf-installer (~> 0.12)
    jekyll-sass-converter (1.5.1)
      sass (~> 3.4)
    jekyll-scholar (5.11.0)
      bibtex-ruby (~> 4.0, >= 4.0.13)
      citeproc-ruby (~> 1.0)
      csl-styles (~> 1.0)
      jekyll (~> 3.0)
    jekyll-seo-tag (2.4.0)
      jekyll (~> 3.3)
    jekyll-watch (2.0.0)
      listen (~> 3.0)

Jekyll v4.0.0 support is missing

This plugin is limited to Jekyll version 2.0 and 3.1 jekyll (>= 2.0, ~> 3.1) what about version 4.0.0 jekyll (~> 4.0.0). Is there a way to use it with Jekyll v4?

PDFs generated using Markdown content

The PDFs generated by the plugin appear to have the raw markdown content embedded in them instead of the generated HTML.

Is there an undocumented setting to get the generated contents instead of the raw markdown within the PDFs?

Could not find a valid gem 'digest'

Is there something that I am missing?

gem install jekyll-pdf
ERROR:  Could not find a valid gem 'digest' (~> 0) (required by 'jekyll-pdf' (>= 0)) in any repository
ERROR:  Possible alternatives: acts_as_digested_on, application_digester, attr_digest, cache_digests, carrierwave-digest, digest, digest-base32, digest-blake2b, digest-blake3, digest-cmac

New Repository/Fork

As this (the main repo) was abandoned in 2017, I decided to open a new organization in order to be able to continue. the new repo is here:
https://github.com/jekyll-pdf/jekyll-pdf

I forked from the fork that seemed most alive (as of 28. June 2019),
and I invite(d) a few contributors that had at some point committed to the project,
even if mostly just in their own forks.

undefined method try_require

I got an Error if i try bulid the site with Jekyll 3.3.0

/Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf/liquid/tags/jekyll-assets.rb:1:in `<top (required)>': undefined method `try_require' for main:Object (NoMethodError)
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf.rb:1:in `require'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf.rb:1:in `block in <top (required)>'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf.rb:1:in `each'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf.rb:1:in `<top (required)>'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-pdf-0.1.6/lib/jekyll-pdf.rb:1:in `require'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-pdf-0.1.6/lib/jekyll-pdf.rb:1:in `<top (required)>'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.3.0/lib/jekyll/external.rb:43:in `require'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.3.0/lib/jekyll/external.rb:43:in `block in require_with_graceful_fail'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.3.0/lib/jekyll/external.rb:40:in `each'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.3.0/lib/jekyll/external.rb:40:in `require_with_graceful_fail'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.3.0/lib/jekyll/plugin_manager.rb:27:in `require_gems'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.3.0/lib/jekyll/plugin_manager.rb:19:in `conscientious_require'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.3.0/lib/jekyll/site.rb:111:in `setup'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.3.0/lib/jekyll/site.rb:33:in `initialize'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.3.0/lib/jekyll/commands/doctor.rb:21:in `new'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.3.0/lib/jekyll/commands/doctor.rb:21:in `process'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.3.0/lib/jekyll/commands/doctor.rb:15:in `block (2 levels) in init_with_program'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
	from /Users/doc/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.3.0/exe/jekyll:13:in `<top (required)>'
	from /Users/doc/.rbenv/versions/2.3.1/bin/jekyll:23:in `load'
	from /Users/doc/.rbenv/versions/2.3.1/bin/jekyll:23:in `<main>'

An idea what caused this?

Build issue : Digest gem not accessible anymore

RubyGem.org : "The gem digest is no longer accessible, as the name was in the reserved namespace we've locked off -- it was only in the search results by accident, and we no longer are able to provide access to it via rubygems.org. I apologize for any disruption this has caused you!"

discussion

Error: undefined method `data' for nil:NilClass

I'm getting the following output, when trying to build my Jekyll site using jekyll-pdf:

yzjm@yzsputnik:/yz/mxdocs$ jekyll build -t
Configuration file: /yz/mxdocs/_config.yml
            Source: /yz/mxdocs
       Destination: /yz/mxdocs/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
/home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf/document.rb:46:in `getConfig': undefined method `data' for nil:NilClass (NoMethodError)
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf/document.rb:25:in `initialize'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf/generator.rb:11:in `new'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf/generator.rb:11:in `block (2 levels) in generate'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf/generator.rb:10:in `each'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf/generator.rb:10:in `block in generate'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf/generator.rb:9:in `each'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-pdf-0.1.6/lib/jekyll/pdf/generator.rb:9:in `generate'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-3.3.1/lib/jekyll/site.rb:174:in `block in generate'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-3.3.1/lib/jekyll/site.rb:172:in `each'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-3.3.1/lib/jekyll/site.rb:172:in `generate'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-3.3.1/lib/jekyll/site.rb:68:in `process'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-3.3.1/lib/jekyll/command.rb:26:in `process_site'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-3.3.1/lib/jekyll/commands/build.rb:63:in `build'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-3.3.1/lib/jekyll/commands/build.rb:34:in `process'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-3.3.1/lib/jekyll/commands/build.rb:16:in `block (2 levels) in init_with_program'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/gems/jekyll-3.3.1/exe/jekyll:13:in `<top (required)>'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/bin/jekyll:22:in `load'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/bin/jekyll:22:in `<main>'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in `eval'
	from /home/yzjm/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in `<main>'

Has anyone any idea what might be causing this?

jekyll-pdf-0.1.7 dependecies does not include digest (~> 0)

When running bundle with ruby 2.6.1 and no other non jekyll starter gems installed.

Fetching jekyll-pdf 0.1.7
Downloading jekyll-pdf-0.1.7 revealed dependencies not in the API or the lockfile (digest (~> 0)).
Either installing with `--full-index` or running `bundle update jekyll-pdf` should fix the problem.

URL encoding paths

I've managed to setup the plugin however I am running into a weird issue. The generated pdfs end up in the wrong folder. For example: administrator%20articles instead of administrator articles.

Is there a setting to generate the PDFs in the correct directory?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.