Git Product home page Git Product logo

fill-pdf's Introduction

FillPdf

Description

This gem is a Ruby on Rails plugin. It permit to fill pdf form.

Installation

Add these lines to your Gemfile:

gem 'fill_pdf', git: "https://github.com/CapSens/fill-pdf"

Configuration

The following configuration items are available through the config object in application.rb:

class Application < Rails::Application
  # ...
  # ...
  # This is required to generate document and save it.
    config.fill_pdf.output_path = ''

  # This is required. It is a pdftk library path. Linux('/usr/bin/pdftk'), OSX('/usr/local/pdftk')
  if RUBY_PLATFORM.include? "darwin"
    config.fill_pdf.pdftk_path = '/usr/local/bin/pdftk'
  else
    config.fill_pdf.pdftk_path = '/usr/bin/pdftk'
  end
end

Conventions

  • All Hash keys must be string

  • Template is a path of your pdf file

Usage

Describe FillPdf initializer

def initialize(template, dictionary={})
  @attributes = {}
  @template = template
  @dictionary = dictionary
  @pdftk = PdfForms.new(Rails.application.config.fill_pdf.pdftk_path)
end

# Template is a path of a template file.
# dictionary is a hash contains pdf fields values. This hash keys should be pdf fields names.

Dictionary example

def action
  dictionary = {
    name: 'Armand Niampa',
    address: '80 rue des haies, 75020 Paris, France',
    created_at: '20/01/2015/',
    payed_at: '20/01/2015/',
    monthly_payment: '200 €',
    amount: '2000 €',
    deduction_amount: '300 €'
  }

  # dictionary key represent template field
  # value represent field value

  #...
  #...
end

Use plugin to generate and download document

def action
  dictionary = {
    name: 'Armand Niampa',
    address: '80 rue des haies, 75020 Paris, France',
    created_at: '20/01/2015/',
    payed_at: '20/01/2015/',
    monthly_payment: '200 €',
    amount: '2000 €',
    deduction_amount: '300 €'
  }

  begin
    template = Rails.root.join('public', 'pdf_templates', 'pdf_file.pdf')
    document = FillPdf::Fill.new(template, dictionary)
    send_file document.export, filename: "name of your new document.pdf", type: 'application/pdf'
  rescue Exception => exception
    logger.warn exception
  end
end

fill-pdf's People

Contributors

ayann avatar hlobit avatar imhide avatar

Watchers

James Cloos avatar  avatar

Forkers

qdegraeve

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.