How to set up pdftk or iText to work with Rails 3 on Heroku?
Asked Answered
H

1

6

I'm trying to find a way to inject FDF file content into a fillable PDF file (provided by customer and not supposed to be 're-drawn' using Prawn or PDFKit), and I think I have to use either iText(with JRuby) or pdftk.

Both of these libs work with no problem on my Ubuntu local machine, but I am wondering how I would get either them to work on Heroku. Has anyone tried to get iText(JRuby) or PDFTK to work on Heroku ?

Thanks for your help!

Houselights answered 23/1, 2011 at 4:19 Comment(0)
R
8

You can use pdftk on Heroku – it's pre-installed. You use it by shelling out to it as a command-line program from within your Ruby app.

For most pdftk commands, you will use Tempfiles. Interpolate the Tempfile#paths in the arguments to pdftk.

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

In some cases, you will be able to pipe data in and out using stdin and stdout rather than Tempfiles.

input = ...
output = IO.popen "pdftk #{subcommand}", 'w+b' do |io|
  io.write input
  io.flush
  io.close_write
  io.read
end
Registry answered 23/1, 2011 at 4:54 Comment(1)
Just a note: It's pre-installed on the Heroku Bamboo stack (which runs Debian), but not yet on the latest stack which is Cedar (runs Ubuntu).Bollay

© 2022 - 2024 — McMap. All rights reserved.