PuppetPdf
PuppetPdf is a lib that wraps Google Puppeteer pdf generation method to be used with Rails.
Installation
Add this line to your application's Gemfile:
gem 'puppet_pdf'
And then execute:
$ bundle
Or install it yourself as:
$ gem install puppet_pdf
Run this task to install some dependencies:
$ rails puppet_pdf:install_dependencies
Usage
Render in a controller
class TasksController < ApplicationController
def pdf
render_pdf
end
end
You can pass some options to render_pdf
like template, layout and the output filename. The available options are:
{
template: String,
layout: String,
filename: String,
header: String,
footer: String,
margins: Hash,
loading_delay: Integer,
output_path: String
}
View Helpers
In you views you need to replace stylesheet_link_tag
with puppet_stylesheet_link_tag
, and javascript_include_tag
with puppet_javascript_script_tag
<!DOCTYPE html>
<html>
<head>
<title>PuppetPdfExample</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= puppet_stylesheet_link_tag('application.css') %>
<%= puppet_javascript_script_tag('application.js') %>
</head>
<body>
<%= yield %>
</body>
</html>
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/puppet_pdf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the PuppetPdf project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.