I’d like to use Ruby/Poppler in a server context (Rails application) to
render PDF documents. However, it appears that the Poppler bindings
require the presence of an X display. For example, the following code
not run outside of an X session:
filename = ARGV
document = Poppler::Document.new(filename)
page = document.get_page(0)
(width, height) = page.size
surface = Cairo::ImageSurface.new(width_pt, height_pt)
context = Cairo::Context.new(surface)
The code fails with:
init': Cannot open display: (Gtk::InitError) from /usr/lib/ruby/1.8/gtk2.rb:12 from /usr/lib/ruby/1.8/poppler.rb:6:inrequire’
from ./test_pdf.rb:2:in `require’
(This is with ruby-gnome2 0.17, poppler 0.8.7 on Debian lenny)
AFAICT native Poppler itself can be used independently of an X session,
it’d be nice to have a way to achieve this using the Ruby bindings.
What would need to be done to make this work?
Any suggestions on how to proceed would be much appreciated.