开发者

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

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 ?

Th开发者_运维问答anks for your help!


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜