Pdf-stamper

Hi,

I have installed both pdf-stamper and rjb on my machine, and when I
tired the following code in my controller code

pdf = PDF::Stamper.new(“YellowReq.pdf”)

I got an error
uninitialized constant HomeController::PDF

I have set up java home
export JAVA_HOME = ‘/Library/Java/Home’

How to set up LD_LIBRARY_PATH on my snow leopard?

Thanks!

On Tue, 2010-03-09 at 16:58 +0100, John Wu wrote:

Hi,

I have installed both pdf-stamper and rjb on my machine, and when I
tired the following code in my controller code

pdf = PDF::Stamper.new(“YellowReq.pdf”)

I got an error
uninitialized constant HomeController::PDF


same error as with other methodology. Did you get the pdf_stamper gem
installed?

gem list --local # does it show?

I have set up java home
export JAVA_HOME = ‘/Library/Java/Home’

How to set up LD_LIBRARY_PATH on my snow leopard?


depends upon what/where you’ve got installed (jre or jdk) but
generally…

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_HOME/jre/lib/i386:
$JAVA_HOME/jre/lib/i386/client

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Hey I tried this way:

irb(main):001:0> require ‘rubygems’
=> false
irb(main):002:0> require ‘rjb’
=> true
irb(main):003:0> load_path =
File.join(’/Library/WebServer/Documents/rubyapps/tproj2/lib/iText.jar’)
=> “/Library/WebServer/Documents/rubyapps/tproj2/lib/iText.jar”
irb(main):004:0> options = []
=> []
irb(main):005:0> Rjb::load load_path, options
=> nil
irb(main):006:0> doc = Rjb::import(“com.lowagie.text.Document”)
NoClassDefFoundError: com/lowagie/text/Document
from (irb):6:in import' from (irb):6 from /usr/local/bin/irb:12:in

Why am I getting this error?

Craig W. wrote:

On Tue, 2010-03-09 at 16:58 +0100, John Wu wrote:

Hi,

I have installed both pdf-stamper and rjb on my machine, and when I
tired the following code in my controller code

pdf = PDF::Stamper.new(“YellowReq.pdf”)

I got an error
uninitialized constant HomeController::PDF


same error as with other methodology. Did you get the pdf_stamper gem
installed?

gem list --local # does it show?

I have set up java home
export JAVA_HOME = ‘/Library/Java/Home’

How to set up LD_LIBRARY_PATH on my snow leopard?


depends upon what/where you’ve got installed (jre or jdk) but
generally…

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_HOME/jre/lib/i386:
$JAVA_HOME/jre/lib/i386/client

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Thanks for the response.

I want to narrow down the problem. It seems to me that rjb can not load
iText even though I installed pdf-stampers as a gem.

I have looked at prawn but it doesn’t have the features I wanted. There
is a bug about installing pdftk on snow leopard.

Craig W. wrote:

I don’t follow at all what you are trying to do and why.

Once you run irb from your local installation instead of running
‘script/console’ from within your rails root directory, you are pretty
much not running rails at all but just basic ruby and at that point, you
are not on topic here.

Then you’ve seeming installed the iText jar files in your rails
application which should have been installed as gems and automatically
loaded from the appropriate ruby/gems path.

The error you are asking about is from rjb which likewise, has nothing
to do with rails.

My own experience with pdf-stamper was with rails 1.2.x and though it’s
a gem and should be functional with current versions of rails I’m a
little hesitant to recommend it because I simply don’t know and that is
why I tried to steer you onto a methodology that didn’t require
java/rjb, especially since I gathered that your experience with ruby and
with rails are somewhat limited.

Craig

On Wed, 2010-03-10 at 20:38 +0100, John Wu wrote:

=> []
Craig W. wrote:



depends upon what/where you’ve got installed (jre or jdk) but
generally…

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_HOME/jre/lib/i386:
$JAVA_HOME/jre/lib/i386/client


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

I don’t follow at all what you are trying to do and why.

Once you run irb from your local installation instead of running
‘script/console’ from within your rails root directory, you are pretty
much not running rails at all but just basic ruby and at that point, you
are not on topic here.

Then you’ve seeming installed the iText jar files in your rails
application which should have been installed as gems and automatically
loaded from the appropriate ruby/gems path.

The error you are asking about is from rjb which likewise, has nothing
to do with rails.

My own experience with pdf-stamper was with rails 1.2.x and though it’s
a gem and should be functional with current versions of rails I’m a
little hesitant to recommend it because I simply don’t know and that is
why I tried to steer you onto a methodology that didn’t require
java/rjb, especially since I gathered that your experience with ruby and
with rails are somewhat limited.

Craig

On Wed, 2010-03-10 at 20:38 +0100, John Wu wrote:

=> []
Craig W. wrote:



depends upon what/where you’ve got installed (jre or jdk) but
generally…

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_HOME/jre/lib/i386:
$JAVA_HOME/jre/lib/i386/client


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

On Wed, 2010-03-10 at 22:24 +0100, John Wu wrote:

Thanks for the response.

I want to narrow down the problem. It seems to me that rjb can not load
iText even though I installed pdf-stampers as a gem.

I have looked at prawn but it doesn’t have the features I wanted. There
is a bug about installing pdftk on snow leopard.


seems to me that my original suggestion was by far the easiest solution
and didn’t require rjb, java or itext. It simply required a class for
Fdf and a web server somewhere (could even be the ‘public’ directory on
your rails server) to serve up the PDF document which is dynamically
loaded when the end user opens the FDF document.

I didn’t know that pdftk wasn’t an option on Macintosh but I am not a
Macintosh fan so I’m not going to lose any sleep over it. Now that I
think about it, pdftk also requires itext so I am wondering if the
problem with pdftk running on your Macintosh is getting itext to run.
What I do recall was that pdftk was entirely useful to me because once I
could assemble and disassemble PDF’s and FDF’s, it all became clear to
me.

pdf-stamper requires a functional rjb which means that you must have a
working ruby/java bridge connection and I suspect that is one of your
issues. Also, it seems to me that there is no reason to put any part of
itext or rjb in your lib/ directory and it might make matters worse.

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

On Thu, 2010-03-11 at 03:19 +0100, John Wu wrote:

    send_data pdf_output, :filename => filename,
                             :type => "application/pdf"
end

end

But the browser can not open the pdf. It says it is empty.

What is the correct way to do this?


I’ve always used send_file myself, send_data might work but I have no
experience with it but I think you’re being sloppy with your command…

pdf_output = pdftk some_file_name.pdf \ fill_form some_file_name.fdf \ output some_new_file_name.pdf

send_file “some_new_file_name.pdf”,
:type => “application/pdf”,
:disposition => ‘inline’

note that you will have to ‘path’ the pdf & fdf files all relative to
the ‘public’ folder.

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

On Wed, 2010-03-10 at 20:15 -0700, Craig W. wrote:

format.pdf do

experience with it but I think you’re being sloppy with your command…
the ‘public’ folder.


and perhaps I don’t need to point this out because you’ve figured it out
already…

make sure you know EXACTLY what the fdf file is supposed to look like so
you can write it from rails.

make sure you test your fdf and pdf files with pdftk from the command
line so you know that they work before you worry about integrating into
rails.

you actually don’t need pdftk and don’t actually need to ‘fill_form’ if
you can put the PDF file on a web server that is accessible by Adobe
Reader because you can embed the URL for the PDF file inside the FDF
file and it will automatically download and do it’s magic on the
client’s computer.

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Thank you so much for your help!

I am finally able to install pdftk. I have a question about how to send
pdf to browser directly.

my code is here:

pdf_output = pdftk #{filename} fill_form #{fdf.path} output
respond_to do |format|
format.pdf do
send_data pdf_output, :filename => filename,
:type => “application/pdf”
end
end

But the browser can not open the pdf. It says it is empty.

What is the correct way to do this?

Craig W. wrote:

On Wed, 2010-03-10 at 22:24 +0100, John Wu wrote:

Thanks for the response.

I want to narrow down the problem. It seems to me that rjb can not load
iText even though I installed pdf-stampers as a gem.

I have looked at prawn but it doesn’t have the features I wanted. There
is a bug about installing pdftk on snow leopard.


seems to me that my original suggestion was by far the easiest solution
and didn’t require rjb, java or itext. It simply required a class for
Fdf and a web server somewhere (could even be the ‘public’ directory on
your rails server) to serve up the PDF document which is dynamically
loaded when the end user opens the FDF document.

I didn’t know that pdftk wasn’t an option on Macintosh but I am not a
Macintosh fan so I’m not going to lose any sleep over it. Now that I
think about it, pdftk also requires itext so I am wondering if the
problem with pdftk running on your Macintosh is getting itext to run.
What I do recall was that pdftk was entirely useful to me because once I
could assemble and disassemble PDF’s and FDF’s, it all became clear to
me.

pdf-stamper requires a functional rjb which means that you must have a
working ruby/java bridge connection and I suspect that is one of your
issues. Also, it seems to me that there is no reason to put any part of
itext or rjb in your lib/ directory and it might make matters worse.

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Thank you!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs