[rjb-users] RJB, iText generates blank pdf

Wes Hays weshays at gmail.com
Fri Dec 14 09:23:51 EST 2007


yuichiro,

Thanks for the reply. I looked into your code vs my code the the main differences is the libraries you are including, which makes sense now that I think more about it.

I also bought the iText book to get a better understanding of what iText can do.  Again, thanks for your help.

Regards,
-Wes


----- Original Message -----
From: "yuichiro" <yuichiro at kuwashima.org>
To: rjb-users at rubyforge.org
Sent: Thursday, December 13, 2007 12:31:14 AM (GMT-0800) America/Los_Angeles
Subject: Re: [rjb-users] RJB, iText generates blank pdf

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
_______________________________________________
rjb-users mailing list
rjb-users at rubyforge.org
http://rubyforge.org/mailman/listinfo/rjb-users



More information about the rjb-users mailing list