How to configure pdftk or iText to work with Rails 3 on Heroku?

I am trying to find a way to add the contents of an FDF file to a fillable PDF file (provided by the client and should not be redrawn using Prawn or PDFKit), and I think I need to use either iText (with JRuby) or pdftk.

Both of these libraries work without problems on my local Ubuntu machine, but I wonder how I can get them to work on Heroku. Has anyone tried to get iText (JRuby) or PDFTK to work on Heroku?

Thank you for your help!

+6
ruby-on-rails jruby itext pdftk heroku
source share
1 answer

You can use pdftk on Heroku - it is pre-installed. You use it by wrapping it as a command line from your Ruby application.

For most pdftk commands pdftk you will use Tempfile s. Interpolate Tempfile#path in pdftk arguments.

 `pdftk #{subcommand}` raise Exception unless $?.success? 

In some cases, you will be able to process data using stdin and stdout rather than Tempfile s.

 input = ... output = IO.popen "pdftk #{subcommand}", 'w+b' do |io| io.write input io.flush io.close_write io.read end 
+8
source share

All Articles