0.0
No commit activity in last 3 years
No release in over 3 years
Write a longer description or delete this line.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.6
~> 1.16
~> 0.7
~> 10.0
~> 3.7
~> 0.16

Runtime

 Project Readme

PDF Templator

Gem Version Build Status Coverage Status

Create PDFs from HTML templates in a breeze.

Features

  • Create a single HTML with <field> tags and PDF Templator will fill them for you.
  • Field types include date, number, date, money, accounting.
  • Create your own field type.
  • Usage as a CLI in case you're not working on Ruby.
  • It uses wicked_pdf internally so you can use all its features too.

Installation

Add this line to your application's Gemfile:

gem 'pdf_templator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pdf_templator

Usage

require 'pdf_templator'

html = File.read('path/to/my/template.html')
# OR
html = '<html>' \
       'My name is <field name="name">' \
       'and today is <field name="date" type="date" data-format="%b %d, %Y">' \
       '</html>'
args = {
  name: 'My Name',
  date: '06/18/2018',
}

reader = PdfTemplator::Reader.new(content: html, footer: footer)
pdf = reader.write(args)
File.open('path/to/file.pdf', 'wb') { |f| f.write(pdf) }

Custom types

module PdfTemplator
  class ListType < Type
    def call
      list = content.split(',')
      html_items = list.map do |item|
        "<li>#{item}</li>"
      end
      "<ul>#{html_items.join}</ul>"
    end
  end
end

# Then you could have an html like

<field name="my_list" type="list"></field>

# And pass the args like

args = {
  my_list: 'car,helicopter,motorcycle'
}

Development

After checking out the repo, run bin/setup to install dependencies. You can also run rake console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pdf_templator.