Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 1b3102b37b
Fetching contributors…

Cannot retrieve contributors at this time

118 lines (75 sloc) 3.911 kb


The pdf_filler Rails plugin makes it easy to update existing PDFs that have form fields defined. Rather then building PDFs in Ruby using something like PDF-Writer, it is much easier to create a PDF in Acrobat, define fields, and update those fields using pdf_filler. An example would be a First/Last name field on a PDF that is possible to update.


This plugin requires RJB (Ruby Java Bridge), so you will need to set your JAVA_HOME environment variable to point your installation of Java.

If your JAVA_HOME environment variable is not setup correctly you will get something like:

Building native extensions.  This could take a while...
ERROR:  Error installing pdf_filler-0.1.0.gem:
        ERROR: Failed to build gem native extension.

/opt/local/bin/ruby extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
extconf.rb:45: JAVA_HOME is not set. (RuntimeError)

Gem files will remain installed in /opt/local/lib/ruby/gems/1.8/gems/rjb-1.1.7 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/rjb-1.1.7/ext/gem_make.out

On my Mac I set JAVA_HOME to be “/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home”.


The recommended method to enable pdf_filler in your project is adding the pdf_filler gem to your environment. Add the following code to your Rails configuration in config/environment.rb: do |config|
  config.gem 'renorb-pdf_filler', :lib => 'pdf_filler', source => ''

Run sudo rake gems:install to install the gem.

Another alternative is to install pdf_filler as a Rails plugin:

script/plugin install git://


  1. You will need a PDF that has form fields to fill.

  2. A writable directory to store the generated PDFs.

  3. For a single page use the Page object?

    // ** Single page **
    page ='/path/to/template.pdf')
    page.set_text(:full_name, 'Wes Hays')
  4. For a collection of pages to be added to a single PDF use a Book object.

    book =
    page1 ='/path/to/template1.pdf')
    page1.set_text(:full_name, 'Wes Hays')
    page2 ='/path/to/template2.pdf')
    page2.set_text(:full_name, 'Darren Johnson')
  5. Rather then setting all the fields manually a PDF can be mapped to an ActiveRecord model. The model must use the acts_as_pdf_db_mapper module. (See rdocs on acts_as_pdf_db_mapper for more options)

    class User < ActiveRecord::Base
    user = User.first
    page ='/path/to/template1.pdf')

Note: You can use the shorter kernel methods PDFPage instead of The same goes for PDFBook instead of


page = PDFPage('/path/to/template.pdf')
book = PDFBook()


This plugin is released under the MIT license. Please contact weshays ( or djohnson ( for any questions.

Jump to Line
Something went wrong with that request. Please try again.