Nguyên the PDF Field Merger
A very lightweight library that fill PDF forms using XFDF/FDF with pdftk
You could download pdftk at http://www.accesspdf.com/pdftk/
Nguyên is a fork of Jens Krämer's pdf-forms with addition of filling forms with XFDF feature.
EXAMPLE:
FDF creation
fdf = Nguyen::Fdf.new(key: 'value', other_key: 'other value')
puts fdf.to_fdf
fdf.save_to('path/to/file.fdf')
XFDF creation
xfdf = Nguyen::Xfdf.new(key: 'value', other_key: 'other value')
puts xfdf.to_xfdf
xfdf.save_to('path/to/file.xfdf')
Query form fields and fill out PDF forms with pdftk
pdftk = Nguyen::PdftkWrapper.new('/usr/local/bin/pdftk')
pdftk.get_field_names('path/to/form.pdf')
fdf = Nguyen::Fdf.new(foo: 'bar')
pdftk.fill_form('/path/to/form.pdf', 'myform.pdf', fdf)
xfdf = Nguyen::Xfdf.new(foo: 'bar')
pdftk.fill_form('/path/to/form.pdf', 'myform.pdf', xfdf)
xfdf_string = <<XML
<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"><fields><field name="foo"><value>bar</value></field></fields></xfdf>
XML
pdftk.fill_form('/path/to/form', 'myform.pdf', xfdf_string)
INSTALL:
gem install nguyen
Source Code:
git clone http://github.com/ruby-journal/nguyen.git
Contribution:
I greatly welcome contributions, please feel free to fork and submit pull request.
LICENSE
see LICENSE