3

I'm trying to send a pdf back to the user but I'm having serious problem getting send_file and send_data to work. I created the pdf file as follows:

tmp = Tempfile.new('filled')
new_tmp_path = PDFPrint.fill_form_using_pdftk(template_path, tmp.path)
send_file (new_tmp_path, :filename => 'filled.pdf')

The browser prompts for a download, but the downloaded filled.pdf file has zero byte. I have verified that new_tmp_path does contain a valid pdf (good, filled content)

I have tried this:

File.open(new_tmp_path, 'r') do |f|
  send_data(f.read, :filename => "filled.pdf")
end

But this also gives me the same download->zero-byte problem, while the file on server (new_tmp_path) has perfect content.

Regards,

Dominic
  • 341
  • 2
  • 5
  • 15

1 Answers1

1

Try sending a simple file to see if it works

send_file '/path/to.jpeg', :type => 'image/jpeg', :disposition => 'inline'

Read this thread, I think it has everything you need.

Community
  • 1
  • 1
Mirko
  • 5,207
  • 2
  • 37
  • 33
  • It turned out that I had to "flush" the file created by PDFTK before sending it. Sorry for not mentioning more details in the question. – Dominic Feb 10 '11 at 15:27