Filling In Existing Forms

180 views
Skip to first unread message

Randy Parker

unread,
Nov 18, 2009, 1:11:41 PM11/18/09
to Prawn
I've been using Prawn to draw boxes containing text such as names &
addresses in specific locations, and then printing the pdf to an
impact printer loaded with pre-printed legal forms. This works,
subject to all the hassles of an impact printer, and the vagaries of
precision form alignment.

On Sept 22, Jeff Cohen asked about using prawn to print into the
editable area of an existing pdf form, and received a reply to the
effect of "prawn can't do that yet". I'd like to do the same thing.

Two questions:

1) Can I use some kind of layers to essential draw an existing pdf
form as a base layer or watermark image, and then print my names &
addresses on another layer (which I align just as meticulously by hand
as I currently do for the impact printers)?

2) Can you outline what would be involved in extending Prawn to do
what Jeff asked? That is, create a pdf with editable areas of fixed
location, size, and font, and then use prawn to write into those
areas?

Though it may not matter, I don't currently have the forms as pdf
documents. I'll have to painstakingly create them by hand so that
they look as much as possible like the current pre-printed ones. One
fellow here suggests doing the layout in Microsoft Word, and exporting
the blank form to pdf. He also proposes using Word's mail-merge
facility to populate the "editable areas" from our Rails app, instead
of prawn.

- Randy

Henrik Nyh

unread,
Nov 18, 2009, 1:16:30 PM11/18/09
to prawn...@googlegroups.com
On Wed, Nov 18, 2009 at 19:11, Randy Parker <randy.j...@gmail.com> wrote:
> 2) Can you outline what would be involved in extending Prawn to do
> what Jeff asked?  That is, create a pdf with editable areas of fixed
> location, size, and font, and then use prawn to write into those
> areas?

There is prawn-forms (http://github.com/yob/prawn-forms) but when I
played with it the other day, it was very, very limited. You can
basically create editable areas and control their position, width and
default text but little else: not height or font.

I had a look at the PDF spec and experimented a little but had little
success, likely because I don't have a good grasp of where things go
in the PDF format. prawn-forms is very little code, though, so if you
know the spec or have time to learn, it's probably not that hard to
add.

Gregory Brown

unread,
Nov 18, 2009, 1:18:14 PM11/18/09
to prawn...@googlegroups.com
For both of these questions, James is more qualified to answer. But...

On Wed, Nov 18, 2009 at 1:11 PM, Randy Parker <randy.j...@gmail.com> wrote:

> 1) Can I use some kind of layers to essential draw an existing pdf
> form as a base layer or watermark image, and then print my names &
> addresses on another layer (which I align just as meticulously by hand
> as I currently do for the impact printers)?

Might be worth looking into the PDF templates[1] stuff James is
working on, or if you wanted to import your PDF as a vector image,
check out PrawnVectorImport[2]

[1] http://github.com/yob/prawn/tree/templates
[2] http://github.com/Bluejade/PrawnVectorImport

> 2) Can you outline what would be involved in extending Prawn to do
> what Jeff asked?  That is, create a pdf with editable areas of fixed
> location, size, and font, and then use prawn to write into those
> areas?

There is a start at:
http://github.com/yob/prawn-forms

But it isn't really functionally useful yet. I'm sure that if your
business throws James some monies, he'd probably round it out.
Otherwise, i'm sure he'll be happy to provide an outline.

> Though it may not matter, I don't currently have the forms as pdf
> documents.  I'll have to painstakingly create them by hand so that
> they look as much as possible like the current pre-printed ones.  One
> fellow here suggests doing the layout in Microsoft Word, and exporting
> the blank form to pdf.  He also proposes using Word's mail-merge
> facility to populate the "editable areas" from our Rails app, instead
> of prawn.

I have no idea about whether that makes sense to do, but it sounds
like a massive kludge to me :)
I'd at least look at what pdftk and other similar tools have to offer.

James Healy

unread,
Nov 18, 2009, 7:39:44 PM11/18/09
to prawn...@googlegroups.com
Gregory Brown wrote:
> > 1) Can I use some kind of layers to essential draw an existing pdf
> > form as a base layer or watermark image, and then print my names &
> > addresses on another layer (which I align just as meticulously by hand
> > as I currently do for the impact printers)?
>
> Might be worth looking into the PDF templates[1] stuff James is
> working on, or if you wanted to import your PDF as a vector image,
> check out PrawnVectorImport[2]

Templating is probably the way to go if you'll be filling the form
content from with your app. prawn-forms was a proof-of-concept for
Interactive Forms - they're designed to be filled in by users in their
PDF reader.

The templating code has progressed nicely, I'm hoping to post a proper
update on its status later today. The short version is i'm hopeful it
can be merged for prawn 0.7.

-- James Healy <ji...@deefa.com> Thu, 19 Nov 2009 11:38:44 +1100

Randy Parker

unread,
Nov 19, 2009, 3:51:21 PM11/19/09
to prawn...@googlegroups.com
James Healy's templating extension to Prawn does exactly what I needed!!

I cloned James' fork of prawn/templates_0_6_3 :
git clone git://github.com/yob/prawn.git

and installed the dependencies:
$>   sudo gem install test-spec, pdf-reader, mocha

cd prawn
git submodule init
git submodule update
git pull origin templates_0_6_3
git checkout templates_0_6_3
rake gem
sudo gem install pkg/prawn-core-0.6.3.99.gem
cd ..
rake gem
gem install pkg/pdf-reader-0.8.0.gem     (a regular "sudo gem install pdf-reader" does not get a current enough one)

Then I simply copied examples/general/template.rb  to another name: legal_form.rb
Added a "require 'rubygems' " line to the top, changed the imported "base" template pdf filename to be my legal form filename, and used a series of simple commands to draw specifically sized text at specific X,Y coordinates:

# zero the margins to allow the direct use of Skim coordinates (see below)
pdf = Prawn::Document.new(:template => filename,   
                                          :margin => [0,0,0,0] ) 

pdf.font_size = 10
pdf.text 'RJI Enterprises Co Inc',   :at => [27,729]
...

And that's it.  I've done several forms with two dozen fields each by opening the various blank 'base' PDFs in the OSX program 'Skim' to get the X,Y locations of each field from Skim's 'Select' tool  (coordinates reported the bottom right of the window)

Mighty nice!

Thanks for your help,
- Randy

James Healy

unread,
Nov 19, 2009, 6:26:58 PM11/19/09
to prawn...@googlegroups.com
Randy Parker wrote:
> James Healy's templating extension to Prawn does exactly what I needed!!

Great! Thanks to some generous sponsorship I was able to push
development on the branch forward earlier this week and it's now it a
fairly usable state.

If anyone else is interested in trying it out, Randy's instructions are
a good guide. The only thing I'd say is I released a new version of the
pdf-reader gem to gemcutter last night, so there should be no need to
build that manually.

Not all PDFs will be useable as templates, there are a few optional
features of the spec that pdf-reader fails to parse. If you find a file
that fails, please send me a copy so I can look into it. All
prawn-generated PDF files should work just fine as a template.

Finally, you'll want to avoid adding content to a template page that
will auto-wrap onto a new page (like auto-wrapped text). I haven't
tested what happens, but I'm sure the results will not be what you
expect.

-- James Healy <ji...@deefa.com> Fri, 20 Nov 2009 10:24:42 +1100

Randy Parker

unread,
Nov 20, 2009, 6:39:22 AM11/20/09
to prawn...@googlegroups.com
For the record, the legal forms I used as base templates were not generated by Prawn.  Other folks in the company created them in MS Word so that they'd look like the official forms, and then just picked "Export as PDF" from Word.

- Randy


--

You received this message because you are subscribed to the Google Groups "Prawn" group.
To post to this group, send email to prawn...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/prawn-ruby?hl=.





--
http://mobiledyne.com

Brett Neumeier

unread,
Nov 23, 2009, 1:53:26 PM11/23/09
to prawn...@googlegroups.com
On Thu, Nov 19, 2009 at 2:51 PM, Randy Parker <randy.j...@gmail.com> wrote:
> James Healy's templating extension to Prawn does exactly what I needed!!
[...]
> pdf = Prawn::Document.new(:template => filename,
>                                           :margin => [0,0,0,0] )
> pdf.font_size = 10
> pdf.text 'RJI Enterprises Co Inc',   :at => [27,729]

I was trying to use the templating extension as well. What I want to
do, though, is use a different font for new text that's being added to
the filled-out document:

pdf = Prawn::Document.new(:template => filename,
:margin => [0,0,0,0] )
pdf.font('myfont.ttf', :size => 12)
pdf.text 'RJI Enterprises Co Inc', :at => [27,729]

results in:
font.rb:285:in `add_to_current_page': undefined method `merge!' for
#<Prawn::Reference:0xb775e7a4> (NoMethodError)
(stack trace follows)

Is this supposed to work? Is there a way to get that to work?

Cheers!

bn

--
Brett Neumeier (bneu...@gmail.com)

James Healy

unread,
Nov 23, 2009, 5:43:54 PM11/23/09
to prawn...@googlegroups.com
Brett Neumeier wrote:
> I was trying to use the templating extension as well. What I want to
> do, though, is use a different font for new text that's being added to
> the filled-out document:
>
> pdf = Prawn::Document.new(:template => filename,
> :margin => [0,0,0,0] )
> pdf.font('myfont.ttf', :size => 12)
> pdf.text 'RJI Enterprises Co Inc', :at => [27,729]
>
> results in:
> font.rb:285:in `add_to_current_page': undefined method `merge!' for
> #<Prawn::Reference:0xb775e7a4> (NoMethodError)
> (stack trace follows)
>
> Is this supposed to work? Is there a way to get that to work?

I'd definitely like it to work. Can you please send me a copy of the
file you're using as a template offlist so I can try it out?

-- James Healy <ji...@deefa.com> Tue, 24 Nov 2009 09:43:20 +1100

Brett Neumeier

unread,
Nov 23, 2009, 8:22:50 PM11/23/09
to prawn...@googlegroups.com
On Mon, Nov 23, 2009 at 4:43 PM, James Healy <ji...@deefa.com> wrote:
> I'd definitely like it to work. Can you please send me a copy of the
> file you're using as a template offlist so I can try it out?

Hmm! I was constructing a minimal test case. I find that the bug is
present at 02387d7 but everything works fine at 2a93056. So, no
worries...

Thanks!

--
Brett Neumeier (bneu...@gmail.com)

James Healy

unread,
Nov 23, 2009, 8:29:11 PM11/23/09
to prawn...@googlegroups.com
Brett Neumeier wrote:
> Hmm! I was constructing a minimal test case. I find that the bug is
> present at 02387d7 but everything works fine at 2a93056. So, no
> worries...

Excellent. I suspect 21c0d74 fixed the issue you were hitting.

-- James Healy <ji...@deefa.com> Tue, 24 Nov 2009 12:28:07 +1100
Reply all
Reply to author
Forward
0 new messages