0

I'm using prawn to generate my pdf files and what i'd like to do is to show them in the browser window and at the same time download them to the file system.

I already read this - Rails, Prawn - PDF show up in browser & etc - but it's not what i'm looking for, because using the Prawn render_file, causes to save the pdf file in a project folder, whereas i want the docs to be saved in the user filesystem, in a download folder chosen by the user obviously (which can be done with the Rails send_file or send_data).

So i was looking if it is possible to use the send_file at the same time to download the file and to show it in the browser window, but i didn't find anything.

Other solutions are welcome :)

Community
  • 1
  • 1
sissy
  • 2,908
  • 2
  • 28
  • 54

1 Answers1

0

The main problem is that you would need two separate requests to do this. A possible solution could be that you render the inline PDF in a browser iframe and at the same time start a javascript request to which the server responds with send_file or send_data. The user only has to click once, but there are two requests made to the server, one renders the file as a download, the other sends it as an inline file.

The only caveat I can think of here is that a browser that doesn't support inline rendering of PDF files would start downloading the PDF twice. You'd have to find some way to check for this.

Jaap Haagmans
  • 6,232
  • 1
  • 25
  • 30
  • i see. Thanks for the explaination and for the idea. I will give it a try :) if it fits consider your answer accepted. – sissy Mar 03 '14 at 10:01
  • oh and for the issue of browser not supporting pdf inline rendering there should be no problem in this case, cause it's an application dedicated just to one person, so i can check if he has the right browser. In other cases i'll have to find a better solution – sissy Mar 03 '14 at 10:04
  • i ended up making 2 different buttons: one for downloading and the other to render the document inline. :) thx for the explaination – sissy Mar 06 '14 at 10:36