Skip to content

Ruby middleware/client for breezy-pdf-lite, an HTML -> PDF service powered by Google Chrome

License

Notifications You must be signed in to change notification settings

substancelab/breezy_pdf_lite-ruby

 
 

Repository files navigation

BreezyPDFLite

Build Status Gem Version

A ruby client for BreezyPDFLite, a one-click-to-deploy microservice for converting HTML to PDF with Google Chrome. Send the library a chunk of HTML, get a PDF of it back. Configure how the PDF is rendered via meta tags in the HTML.

Use pragmatically, or as a Rack Middleware.

Installation

Add this line to your application's Gemfile:

gem 'breezy_pdf_lite'

And then execute:

$ bundle

Or install it yourself as:

$ gem install breezy_pdf_lite

Usage

BreezyPDFLite requires some configuration before you can use it. Somewhere in your application (perhaps in config/intializers/breezy_pdf_lite.rb), configure the base_urland the secret_api_key of your service. Get these from your Heroku configuration.

BreezyPDFLite.setup do |config|
  config.secret_api_key = ENV["BREEZYPDF_SECRET_API_KEY"]
  config.base_url = ENV.fetch("BREEZYPDF_BASE_URL", "http://localhost:5001")
end

Middleware

Add the Middleware to your stack.

Ruby on Rails

# config/application.rb
config.middleware.use BreezyPDFLite::Middleware

Any URL ending in .pdf will be intercepted, rendered as HTML, rendered to a PDF, and then returned to the client.

Rack/Sinatra/etc

See example/config.ru

Pragmatic

See example/pragmatic.rb

Examples

Examples depend on the BreezyPDFLite microservice being avialable.

Middleware

BREEZYPDF_SECRET_API_KEY=YOURSECRETKEY BREEZYPDF_BASE_URL=https://YOURHEROKUAPPORWHATEVER.herokuapp.com/ rackup example/config.ru

Visit https://localhost:9292 and click the link to download the PDF.

Pragmatic

BREEZYPDF_SECRET_API_KEY=YOURSECRETKEY BREEZYPDF_BASE_URL=https://YOURHEROKUAPPORWHATEVER.herokuapp.com/ ruby example/pragmatic.rb

The PDF will be downloaded to example/example.pdf

License

See LICENSE.txt.

About

Ruby middleware/client for breezy-pdf-lite, an HTML -> PDF service powered by Google Chrome

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 99.3%
  • Shell 0.7%