[rjb-users] RJB, iText generates blank pdf

yuichiro yuichiro at kuwashima.org
Thu Dec 13 03:31:14 EST 2007


I was able to output it when I tried it in the same way as this web page. 

http://itext.ugent.be/itext-in-action/chapter.php?chapter=16 

*******************************
require 'rjb'
include Rjb
load("/home/kuwashima/Desktop/iText-2.0.7.jar")
Document = import("com.lowagie.text.Document")
PdfWriter = import("com.lowagie.text.pdf.PdfWriter")
FileOutputStream = import("java.io.FileOutputStream")
AcroFields = import("com.lowagie.text.pdf.AcroFields")
PdfReader = import("com.lowagie.text.pdf.PdfReader")
PdfStamper = import("com.lowagie.text.pdf.PdfStamper")
XfdfReader = import("com.lowagie.text.pdf.XfdfReader")
reader = XfdfReader.new("/home/kuwashima/Desktop/Grades.xfdf")
pdfreader = 
PdfReader.new("/home/kuwashima/Desktop/FoobarTranscriptOfRecords.pdf")
stamp = PdfStamper.new(pdfreader, 
FileOutputStream.new("/home/kuwashima/Desktop/hoge.pdf"))
form = stamp.acro_fields()
form.fields = reader
stamp.close
****************************** 

Wes Hays wrote: 

> Is anyone else using RJB and iText to fill PDFs successfully?  I have a pdf that I created in Adobe Acrobat Professional with 3 text fields (Name, Age and Dog) with some additional text on the page.  When I run the following code it generates a pdf with the fields filled in but the other text that I placed on the form is gone. 
> 
> ----------------------------------------
> require 'rjb' # Version 1.0.11
> Rjb::load(RAILS_ROOT + '/java/lib/iText-2.0.7.jar') 
> 
> @byteArrayOutputStream = Rjb::import('java.io.ByteArrayOutputStream')
> @acroFields = Rjb::import('com.lowagie.text.pdf.AcroFields')
> @pdfReader  = Rjb::import('com.lowagie.text.pdf.PdfReader')
> @pdfStamper = Rjb::import('com.lowagie.text.pdf.PdfStamper')      
> @pdfFormField = Rjb::import('com.lowagie.text.pdf.PdfFormField') 
> 
> @baos    = @byteArrayOutputStream.new
> @reader  = @pdfReader.new_with_sig('Ljava.lang.String;', RAILS_ROOT + '/java/data/regform2.pdf')
> @stamper = @pdfStamper.new_with_sig("Lcom.lowagie.text.pdf.PdfReader;Ljava.io.OutputStream;", @reader, @baos)
> @form    = @stamper.getAcroFields() 
> 
> @stamper.close 
> 
> f = File.new(RAILS_ROOT + '/java/data/regform_ruby2.pdf', "w")
> f.syswrite @baos.toString
> f.close
> ----------------------------------------
> _______________________________________________
> rjb-users mailing list
> rjb-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rjb-users


More information about the rjb-users mailing list