[rjb-users] block issue

rjb-users at rubyforge.org rjb-users at rubyforge.org
Thu Jan 25 14:33:46 EST 2007


I'm getting an "unknown method name" error ONLY when I call the method
inside a loop.  RJB is version 1.0.3.  Here is the code.

Rjb::load('lib/itext-1.4.8.jar')
class PDFStamper
  def initialize( fields = {} )
    filestream   = Rjb::import('java.io.FileOutputStream')
    acrofields   = Rjb::import('com.lowagie.text.pdf.AcroFields')
    pdfreader    = Rjb::import('com.lowagie.text.pdf.PdfReader')
    pdfstamper   = Rjb::import('com.lowagie.text.pdf.PdfStamper')

    reader = pdfreader.new("template.pdf")
    stamp = pdfstamper.new( reader, filestream.new('ouput.pdf') )
    form = stamp.getAcroFields()

    fields.each { |key, value| @form.setField( key, value ) }

    stamp.setFormFlattening(true)
    stamp.close
  end
end

If I run this code I'll get this error:

>> pdf = PDFStamper.new( @template.attributes )
RuntimeError: Fail: unknown method name `setField'
        from ./script/../config/../config/../lib/pdf_stamper.rb:21:in
`method_missing'
        from ./script/../config/../config/../lib/pdf_stamper.rb:21:in
`initialize'
        from ./script/../config/../config/../lib/pdf_stamper.rb:20:in
`initialize'
        from (irb):2

However if I replace the "fields.each {}" loop with simply
form.setField( "some_field", "some_value").  It will work perfectly
fine.

To work around this in my code, I just manually set all the fields.
However, I'm guessing other people may hit this problem.

-- 
Jason Yates
jaywhy at gmail.com


More information about the rjb-users mailing list