Tuesday, 5 January 2010

Installing RJB to allow iText to work to allow PDFs to be produced

Tried - and failed - at home on my Ubuntu box. So tried - and succeeded (eventually) on the RHEL5 box at work.
First thing to do was to install and switch over to the Sun JDK from the one that comes as standard in RHEL5 - easier said than done.
However, following - to the letter - the advice at http://www.ja-sig.org/wiki/display/CASUM/HOWTO+Switch+to+Sun+JVM+in+RHEL eventually got that working.
Essentially this means installing the supplementary channel for the RHEL5 subscription. Follow this will tell you how

Then it is just a question of
yum install java-1.6.0-sun-devel

Next problem - running
gem install rjb

resulted in the following:
ERROR: Error installing rjb:
ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby
extconf.rb:48: JAVA_HOME is not set. (RuntimeError)


Some extensive googling and eventually you find how to set JAVA_HOME - which is not that hard (export command), but ... what the hell is it?
After a lot of blundering around I get a new error message

extconf.rb:40:in `open': No such file or directory - /usr/java/jdk1.6.0_17/jre/Home/include (Errno::ENOENT) from extconf.rb:40

Well, at least that is progress. Looking at line 40 you find the following:
inc = p.include(javahome, 'include')
inc = p.include(javahome, 'Home/include') unless File.exists?(inc)


Aha - so all we have to do is to find a directory that has either an include or Home/include subdirectory and is vaguely related to java - and there is a good chance it will work.
On a RHEL x-86_64 box the following allowed me to install the RJB gem:
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-sun-1.6.0.17.x86_64/
gem install rjb

and the very satisfying ...
Successfully installed rjb-1.2.0
So now - all I have to do is to get it to talk to iText - which rather worryingly is described as "a bit tricky" , esp when gem install RJB was described as "the easy bit".

2 comments:

  1. I'd recommend having a look at 'flying saucer' (https://xhtmlrenderer.dev.java.net/). It's a html to pdf converter (it uses itext under the hood) that is damn near acid compliant and includes some of the nice paging stuff from css3 making headers, footers and page numbering really easy. Compared with the prospect of reading and digesting the 400 odd pages of 'itext in action' it seemed like a far better option. I've stumbled over most of the headaches of getting it working so feel free to drop me a line if you have any questions about it. (markaduncan74_at_googlemail.com)

    ReplyDelete
  2. P.S. Thought i'd mention that i've finally hammered rjb onto ubuntu. I'd had both the open-jdk and sun-jdk installed but didn't have a Home/include directory on my machine. But if you do a search for 'jni.h' that will show the include directory the first line from extconf.rb is looking for

    ReplyDelete