PDF Hacks

PDF Hacks

Using Ruby Java Bindings on Dreamhost and Fill PDF Form with iText

I am familiar with iText , but not familiar with Ruby, I know Dreamhost supports Ruby on Rails(ROR), but never have a chance to run a real application, though I have a Dreamhost space.

Getting rjb, also known as “Ruby Java Bindings’ to work in a Dreamhost account can be somewhat problematic. Fortunately, it is also fairly straightforward. You just have to install all the dependencies in the user directory.

In my case, I was setting up a Rails Application that used the iText Java library to fill in PDF documents for user download. Of course, the server environment was not using Sun Java and the Java headers were not present, so gem install rjb failed. Joy.

The first course of action was to do a local install of Java.

Download jdk-6u7-linux-x64.bin and jre-6u7-linux-x64.bin from the Sun Java site. Then create an ~/opt directory and extract the JRE and JDK (you will need to chmod u+x both files then call them from the command line). Move the resulting folders to ~/opt . I renamed the folders to jdk and jre for simplicity.

Now you ensure that user gems are enabled in cPanel. Then add the following 3 lines to ~/.bash_profile

export JAVA_HOME=/home/username/opt/jdk
export GEM_PATH=/home/username/ruby/gems
export GEM_HOME=/home/username/ruby/gems

Run source ~/.bash_profile to load the paths.

Now you can run gem install rjb without any problems. You will likely have to re-install Rails and other gems because we will be telling our Rails app to load gems from the user directory. Just use the regular gem install syntax.

Add the following 2 lines to your config/environment.rb at the top

ENV[‘GEM_PATH’]=’/home/username/ruby/gems’
ENV[‘JAVA_HOME’]=’/home/username/opt/jdk’

That’s pretty much it.

I will concede that these probably aren’t the best instructions, but this is the real meat of the solution. If you keep getting “no such file to load” errors, you will need to extract the gems to the vendor/plugins directory. cd RAILS_ROOT/vendor/plugins and gem unpack gem_name for each problematic gem. I believe this is an issue with Passenger.

Please correct me if I am wrong about any of this, it was a very long day!

source: http://blog.patrick-morgan.net/2008/10/using-ruby-java-bindings-on-dreamhost.html

August 18, 2009 Posted by | Hacks, Linux, Tutorials | , , , , , , , , , | 1 Comment

Open and edit PDF files in OpenOffice

btw,RubyPDF has already introduce this features on August 5, 2008, for details, please visit OpenOffice 3.0 Enhances PDF Export and Releases PDF Import Extension

I get this a lot “How can I open and edit PDF files without having to purchase a costly application like QarkXPress”? Before OpenOffice extensions came about my answer to that would be “Not easily”. But now, thanks to a very useful tool created by Sun, editing a PDF file is as simple as adding an extension to OpenOffice and then opening that PDF for editing.

The Sun PDF Import Extension offers numerous features and, like all OpenOffice extensions, is simple to install. Let’s take a look at what it offers, how it is installed, and how it is used.

Supports

  • The Sun extension includes the following features:
  • Edit font attributs
  • Retain font appearance
  • Converts images and vector graphics
  • Import of password-protected PDF files
  • Import shapes with default styles
  • Colors and bitmap support
  • Levels remain true

Does not support

  • Native PDF forms
  • Proper paragraphs
  • LaTeX PDF
  • Complex vector graphics
  • Table conversion
  • EPS graphics
  • RTL fonts

What should be apparent from the above lists is that the Sun PDF import extension supports primarily the more simple PDF documents. Once a document gets complex, this extension may or may not work.

For details, please visit,Open and edit PDF files in OpenOffice.

August 16, 2009 Posted by | Hacks, Tutorials | , , | Leave a comment