I MAY be able to derive something out of the present example given here
:
http://blog.codeinmotion.com/index.php/2006/12/22/pdf-generation-in-ruby-on-rails/
but this deals with filling out forms. Is there a simpler example that
just allows you to talk to itext , send it some plain text and get back
a pdf and then send that pdf to the user as downloadable / renderable
data?
On Sat, 2008-07-05 at 14:39 +0200, Ather S. wrote:
I MAY be able to derive something out of the present example given here
:
http://blog.codeinmotion.com/index.php/2006/12/22/pdf-generation-in-ruby-on-rails/
but this deals with filling out forms. Is there a simpler example that
just allows you to talk to itext , send it some plain text and get back
a pdf and then send that pdf to the user as downloadable / renderable
data?
sounds like all you really want is pdf-writer
itext is for filling out forms (and by the way, I ended up using a
combination of pdf-stamper gem and some more raw methods because
rjb/itext was incapable of doing checkboxes).
see http://wiki.rubyonrails.org/rails/pages/HowtoGeneratePDFs
Craig
No I do not want pdfwriter because I already tried it and it is
inadequate. It does not have the capabilities I want like putting
pushbuttons on the pdf or encrypting them (pdf writer’s encryption is
broken and removed) but for starters an example would have been nice.
Craig W. wrote:
On Sat, 2008-07-05 at 14:39 +0200, Ather S. wrote:
I MAY be able to derive something out of the present example given here
:
http://blog.codeinmotion.com/index.php/2006/12/22/pdf-generation-in-ruby-on-rails/
but this deals with filling out forms. Is there a simpler example that
just allows you to talk to itext , send it some plain text and get back
a pdf and then send that pdf to the user as downloadable / renderable
data?
sounds like all you really want is pdf-writer
itext is for filling out forms (and by the way, I ended up using a
combination of pdf-stamper gem and some more raw methods because
rjb/itext was incapable of doing checkboxes).
see http://wiki.rubyonrails.org/rails/pages/HowtoGeneratePDFs
Craig
Are you following my question ? Or do you like to come up with
tangential issues ?
I will write up a simple example and put it up myself
Craig W. wrote:
pdf-writer comes with a chunky bacon example if I recall correctly.
You could always ‘post-process’ a pdf file with pdftk to encrypt it.
Don’t know about pushbuttons in pdf’s
As far as I know, the rails wiki page on PDF that I linked in the
previous e-mail is the exhaustive resource on integrating PDF’s with
rails.
Craig
pdf-writer comes with a chunky bacon example if I recall correctly.
You could always ‘post-process’ a pdf file with pdftk to encrypt it.
Don’t know about pushbuttons in pdf’s
As far as I know, the rails wiki page on PDF that I linked in the
previous e-mail is the exhaustive resource on integrating PDF’s with
rails.
Craig
require ‘rjb’
Rjb::load(‘iText-2.1.2u.jar’)
filestream = Rjb::import(‘java.io.FileOutputStream’)
pdf_writer = Rjb::import(“com.lowagie.text.pdf.PdfWriter”)
document = Rjb::import(“com.lowagie.text.Document”)
par = Rjb::import(“com.lowagie.text.Paragraph”)
ps = Rjb::import(“com.lowagie.text.PageSize”)
chunk = Rjb::import(“com.lowagie.text.Chunk”)
font = Rjb::import(“com.lowagie.text.Font”)
#ff = Rjb::import(“com.lowagie.text.FontFactory”)
bf = Rjb::import(“com.lowagie.text.pdf.BaseFont”)
#ff.register(“C:\WINDOWS\Fonts\CALIBRIB.TTF”, “calibri”);
arial =
bf.createFont(
“C:\WINDOWS\Fonts\CALIBRIB.TTF”,
bf.IDENTITY_H,
bf.NOT_EMBEDDED);
m = filestream.new(“asdasd.pdf”)
document= document.new()
writer= pdf_writer.getInstance(document,m)
#writer.closeStream = false
document.open()
document.add(par.new("Hello World!", font.new(arial)))
document.add(par.new("Now I run on Rails!", font.new(arial)))
document.add(par.new("àÎÉËÏÄ ÐÁÛÅÔ!!!!", font.new(arial)))
document.close
m.close
On Jul 5, 4:39špm, Ather S. [email protected]
Cool that is what I was looking for … I have some of it abstracted to
a java class; Do I send m to the render method ?
miv wrote:
require ‘rjb’
Rjb::load(‘iText-2.1.2u.jar’)
#ff.register(“C:\WINDOWS\Fonts\CALIBRIB.TTF”, “calibri”);
arial =
bf.createFont(
“C:\WINDOWS\Fonts\CALIBRIB.TTF”,
bf.IDENTITY_H,
bf.NOT_EMBEDDED);
m = filestream.new(“asdasd.pdf”)
document= document.new()
writer= pdf_writer.getInstance(document,m)
#writer.closeStream = false
document.open()
document.add(par.new(“Hello World!”, font.new(arial)))
document.close
m.close
RJB cant seem to be able to load iText-2.1.2u.jar; where is this placed?
I tried placing it the c:/ruby/lib folder
then in the lib folder and then in the folder where I was running irb ;
then in the jdk’s lib and still was unable to locate this jar. it keeps
returning nil;
and when I call chunk for example it gives me classdefnotfound etc.
miv wrote:
require ‘rjb’
Rjb::load(‘iText-2.1.2u.jar’)
Craig W. wrote:
On Mon, 2008-07-07 at 04:15 +0200, Ather S. wrote:
require ‘rjb’
Rjb::load(‘iText-2.1.2u.jar’)
I use the pdf-stamper gem and it incorporates itext with the gem (in the
ext folder)
Craig
You expect me to install pdf-stamper even though i am not using pdf
stamper? and I should install pdfstamper just so I can get to the itext
libraries?
I dont think that is a good idea, I dont know what everyone else thinks
about this.
I tried putting the jars in rjb’s ext folder but that didnt work.
On Mon, 2008-07-07 at 04:15 +0200, Ather S. wrote:
require ‘rjb’
Rjb::load(‘iText-2.1.2u.jar’)
I use the pdf-stamper gem and it incorporates itext with the gem (in the
ext folder)
Craig
On Mon, 2008-07-07 at 04:54 +0200, Ather S. wrote:
You expect me to install pdf-stamper even though i am not using pdf
stamper? and I should install pdfstamper just so I can get to the itext
libraries?
I dont think that is a good idea, I dont know what everyone else thinks
about this.
I tried putting the jars in rjb’s ext folder but that didnt work.
no - I don’t expect you to do anything. I’m just relating that the
pdf-stamper gem automatically brings the itext.jar in with it and it is
automatically loaded when you load PDF::Stamper.
I suppose you could load the gem just to see how that gem makes use of
it but the choice is yours.
The gem loads it like this…
Rjb::load(File.join(File.dirname(FILE), ‘…’, ‘…’, ‘ext’,
‘itext-2.0.4.jar’))
Craig
I placed jar in the same folder as script. I think any folder in PATH
will do. Does any other java lib working? may be problem in jvm
version?
On 7 ÉÀÌ, 06:15, Ather S. [email protected]
Yes String is working for example from the irb interface.
I have placed the jar file in script but when I type
Rjb::load(‘iText-2.1.2u.jar’) I get an error saying
RuntimeError : unknown error
from (irb):2: in ‘initialize’
from (irb):2: in ‘dlopen’
from (irb):2: in ‘load’
miv wrote:
I placed jar in the same folder as script. I think any folder in PATH
will do. Does any other java lib working? may be problem in jvm
version?
On 7 , 06:15, Ather S. [email protected]
Is there a way of sending this pdf file asdasd.pdf to the browser ; Send
binary data to the user as a file download as follows :
send_data(BINARY_DATA,{:filename=>“asasd.pdf”,:type=>“application/pdf”})
send_data at :
What is BINARY_DATA below? is it document, m, pwf_writer?
BTW I am still unable to load this jar file using rjb … you are
welcome to see here :
http://rubyforge.org/forum/forum.php?thread_id=26875&forum_id=8190
miv wrote:
require ‘rjb’
Rjb::load(‘iText-2.1.2u.jar’)
filestream = Rjb::import(‘java.io.FileOutputStream’)
pdf_writer = Rjb::import(“com.lowagie.text.pdf.PdfWriter”)>
document = Rjb::import(“com.lowagie.text.Document”)
m = filestream.new(“asdasd.pdf”)
document= document.new()
writer= pdf_writer.getInstance(document,m)
document.open()
document.add(par.new(“Hello World!”, font.new(arial)))
document.add(par.new(“Now I run on Rails!”, font.new(arial)))
document.close
m.close
On Mon, 2008-07-14 at 03:14 +0200, Ather S. wrote:
last line of the above blog (that is I can generate the document and
I try to do a byte[].toString() and send that to send_data but when I
get byte[].toString() from the java classes I get an error :
No Class DefFoundError (org/bouncycastle/asn1/ASN1OctetString)
Where to go from here?
From the blog : Is there an equivalent to String.from_java_bytes in
ruby?
I can’t help here except that I save the PDF to a file and then use
send_file and it’s all fairly simple.
Craig
Craig W. wrote:
On Mon, 2008-07-14 at 03:14 +0200, Ather S. wrote:
last line of the above blog (that is I can generate the document and
I try to do a byte[].toString() and send that to send_data but when I
get byte[].toString() from the java classes I get an error :
No Class DefFoundError (org/bouncycastle/asn1/ASN1OctetString)
Where to go from here?
From the blog : Is there an equivalent to String.from_java_bytes in
ruby?
I can’t help here except that I save the PDF to a file and then use
send_file and it’s all fairly simple.
Craig
OK!! that works … I am at a point where this maybe inefficient but I
will take it! Thanks !
You can use send_data by passing it a bytearray!!! no need for
String.fromjavabytes…
Craig W. wrote:
On Mon, 2008-07-14 at 03:14 +0200, Ather S. wrote:
last line of the above blog (that is I can generate the document and
I try to do a byte[].toString() and send that to send_data but when I
get byte[].toString() from the java classes I get an error :
No Class DefFoundError (org/bouncycastle/asn1/ASN1OctetString)
Where to go from here?
From the blog : Is there an equivalent to String.from_java_bytes in
ruby?
I can’t help here except that I save the PDF to a file and then use
send_file and it’s all fairly simple.
Craig
I am still attempting to figure out how to send an Itext generated pdf
Document to the browser.
I am looking at the following blog posting where someone is using jruby
and iText to create a pdf file and then sending it to the browser :
http://codersifu.blogspot.com/2007/06/howto-generate-pdf-files-in-ruby-on.html
Unlike the above example I am using only ruby / on rails.
I would like to do precisely this in ROR and I can get to the second
last line of the above blog (that is I can generate the document and
even the toByteArray or byte[] ). As in the example:
document.close // <<<--- I can get this document
send_data String.from_java_bytes(m.toByteArray),
:type=> "application/pdf", :dispostion=>"inline"
// I can call the toByteArray and get the array of bytes byte[]
but I dont know how to send_data to the browser with the document and
byetarraystream available.
I try to do a byte[].toString() and send that to send_data but when I
get byte[].toString() from the java classes I get an error :
No Class DefFoundError (org/bouncycastle/asn1/ASN1OctetString)
Where to go from here?
From the blog : Is there an equivalent to String.from_java_bytes in
ruby?
Ather S. wrote:
Is there a way of sending this pdf file asdasd.pdf to the browser ; Send
binary data to the user as a file download as follows :
send_data(BINARY_DATA,{:filename=>“asasd.pdf”,:type=>“application/pdf”})
send_data at :
ActionController::Streaming
What is BINARY_DATA below? is it document, m, pwf_writer?
BTW I am still unable to load this jar file using rjb … you are
welcome to see here :
http://rubyforge.org/forum/forum.php?thread_id=26875&forum_id=8190
miv wrote:
require ‘rjb’
Rjb::load(‘iText-2.1.2u.jar’)
filestream = Rjb::import(‘java.io.FileOutputStream’)
pdf_writer = Rjb::import(“com.lowagie.text.pdf.PdfWriter”)>
document = Rjb::import(“com.lowagie.text.Document”)
m = filestream.new(“asdasd.pdf”)
document= document.new()
writer= pdf_writer.getInstance(document,m)
document.open()
document.add(par.new(“Hello World!”, font.new(arial)))
document.add(par.new(“Now I run on Rails!”, font.new(arial)))
document.close
m.close
Ok following is a posting on blogger about using itext using ROR:
Is there a better blogging site. I cannot format the code properly on
this one?
How do I format it nicer?
Ather S. wrote:
You can use send_data by passing it a bytearray!!! no need for
String.fromjavabytes…