From ediestel at pol.net Tue Aug 21 22:06:56 2007 From: ediestel at pol.net (Eckhart Diestel) Date: Tue, 21 Aug 2007 16:06:56 -1000 Subject: [Pdf-stamper-devel] pdf/stamper Message-ID: <58426A60-1E32-4D8A-A2AF-1D2297BEBC3C@pol.net> Hi, I am not sure how to use this list. this is working with irb after installation plus configuration of RJB and download/local gem install of pdf_ stamper: # test_template.pdf in root directory of application. require 'rubygems' require 'fileutils' require 'rjb' require 'tmpdir' include FileUtils Rjb::load('/usr/local/lib/ruby/gems/1.8/gems/pdf_stamper-0.2.0/ext/ itext-2.0.4.jar') # decided to put full path here require 'pdf/stamper' pdf = PDF::Stamper.new("test_template1.pdf") pdf.text :name, "joe" pdf.save_as "my_output1.pdf" # => "my_output.pdf" what would be the correct synthax to iterate over a result set ? require 'rubygems' require 'fileutils' require 'rjb' require 'tmpdir' include FileUtils Rjb::load('/usr/local/lib/ruby/gems/1.8/gems/pdf_stamper-0.2.0/ext/ itext-2.0.4.jar') @cm1500 = Cm1500.find(params[:id]) require 'pdf/stamper' pdf = PDF::Stamper.new("test_template1.pdf") for column in Cm1500.content_columns pdf.text( column.name, cm1500.send(column.name) ) # throws unknown method error 'cm1500 unknown ...' Eckhart PS: some minor inconsistencies with use of - and _, such as test- template.pdf vs test_template; this is also the case for the file name in the repository, if I remember correctly it has file name 'pdf-stamper-0.2.0', while it tries to access with 'pdf_stamper-0.2.0' ( mind the underscore), which leads to the 'no such file in any repository' response. From ediestel at pol.net Wed Aug 22 20:42:38 2007 From: ediestel at pol.net (Eckhart Diestel) Date: Wed, 22 Aug 2007 14:42:38 -1000 Subject: [Pdf-stamper-devel] controller example/irb Message-ID: <0B7FA7CD-AE67-48F6-90A7-3E3ACAA94D9E@pol.net> Working example, from irb console, accessing the a database table require 'rubygems' # required gems require 'fileutils' require 'rjb' require 'tmpdir' include FileUtils Rjb::load('/usr/local/lib/ruby/gems/1.8/gems/pdf_stamper-0.2.0/ext/ itext-2.0.4.jar') # loads itext.jar using ruby java bridge; here with full path example require 'pdf/stamper' @patient = Patient.find(:all) # all row from model Patient returned to variable as array pdf = PDF::Stamper.new("test_template1.pdf") # template needs to contain text field(s) with name(s) matching the column name(s) in your database' for patient in @patient # patient instance in variable pdf.text (column.name,patient.send(column.name)) # sets the value to the text field (key.to_s,value.to_s) end pdf.save_as "output.pdf" # self explanatory Eckhart From jaywhy at gmail.com Wed Aug 22 22:03:10 2007 From: jaywhy at gmail.com (Jason Yates) Date: Wed, 22 Aug 2007 22:03:10 -0400 Subject: [Pdf-stamper-devel] controller example/irb In-Reply-To: <0B7FA7CD-AE67-48F6-90A7-3E3ACAA94D9E@pol.net> References: <0B7FA7CD-AE67-48F6-90A7-3E3ACAA94D9E@pol.net> Message-ID: <4cbfccd70708221903g680fe499i8d258cffde71d9d3@mail.gmail.com> > require 'fileutils' > > require 'rjb' > > require 'tmpdir' > > include FileUtils > > Rjb::load('/usr/local/lib/ruby/gems/1.8/gems/pdf_stamper-0.2.0/ext/ > itext-2.0.4.jar') # loads itext.jar using ruby java bridge; here > with full path example > You shouldn't need any of that. If so it is a bug. -- Jason Yates jaywhy at gmail.com