Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slim2pdf

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slim2pdf

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Slim2pdf Code Climate Build Status

Slim2pdf renders slim template with data hash and saves the results as pdf file.

Installation

Add this line to your application's Gemfile:

gem 'slim2pdf'

And then execute:

$ bundle

Or install it yourself as:

$ gem install slim2pdf

Usage

require 'slim2pdf'

Create writer object

writer = Slim2pdf::Writer.new
writer.template = 'template.slim'
writer.data = {name: 'John', surname: 'Doe'}

Set parameters in initializer

writer = Slim2pdf::Writer.new('template.slim', {name: 'John', surname: 'Doe'})

Possible actions

writer.render_to_html # return rendered html as string

writer.save_to_html('output.html') # saves rendered html to file

writer.save_to_pdf('output.pdf') # saves rendered html as pdf file

Changing default wkhtmltopdf path

writer = Slim2pdf::Writer.new
writer.wkhtmltopdf_path = '/your/path/to/wkhtmltopdf'

Wkhtmltopdf params will be generated automatically.

Changing default wkhtmltopdf command with params

writer = Slim2pdf::Writer.new
writer.wkhtmltopdf_command = '/bin/some_wrapper /your/path/to/wkhtmltopdf --your --params'

Input (html) and output (pdf) files will be added automatically.

Examples

Save simple slim template without data to pdf file

require 'slim2pdf'

writer = Slim2pdf::Writer.new('simple.slim')
writer.save_to_pdf('simple.pdf')

See: doc/examples/simple

writer = Slim2pdf::Writer.new('agreement.slim')
writer.data = {date: '2014-01-14', part1: 'Google', part2: 'Microsoft'}
writer.footer_text = 'Agreement footer'
writer.save_to_pdf('agreement.pdf')

See: doc/examples/agreement

Generate bulk invoices

writer = Slim2pdf::Writer.new('invoice.slim')
buyers = ['Buyer A', 'Buyer B', 'Buyer C', 'Buyer D']
buyers.each_with_index do |buyer, index|
  number = index + 1
  writer.data = {
    seller: 'Seller', buyer: buyer, number: "#{number}/2014",
    item_name: 'Service', price: '$100', date: '2014-01-14'
  }
  writer.save_to_pdf("invoice-#{number}.pdf")
end

See: doc/examples/invoices

Debuging

Setting logger

require 'logger'

writer = Slim2pdf::Writer.new
writer.logger = Logger.new(STDERR)

If you use Slim2pdf with Rails, the Rails.logger will be set automatically.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

FAQs

Package last updated on 24 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc