# Generating a pdf from form data and serving it back

**URL:** <https://www.ruby-forum.com/t/generating-a-pdf-from-form-data-and-serving-it-back/72330>\
**Category:** Rails\
**Created:** [October 16, 2006, 3:08pm UTC](https://www.ruby-forum.com/t/generating-a-pdf-from-form-data-and-serving-it-back/72330 "2006-10-16T15:08:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stuart\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9de053/32.png) [@Stuart\_W](https://www.ruby-forum.com/u/Stuart_W)\
**Post date:** [October 16, 2006, 3:08pm UTC](https://www.ruby-forum.com/t/generating-a-pdf-from-form-data-and-serving-it-back/72330/1 "2006-10-16T15:08:35Z")

</div>

hey everybody,

this is unfortunately my second time typing this out since googlegroups  
never posted my first message.

here’s my deal:

working on a rails app where the user fills in some form data and then  
with  
the given info i build a pdf with pdf-writer. after the pdf generates i  
want  
to have a link created on the next page for the user to download the pdf  
to  
their local machine. few questions: where’s the best place to store the  
pdf  
in the rails tree (i imagine somewhere in public) for the user to be  
able to  
download it. also, since many users will be using this interface i need  
a  
mechanism to junk stale reports. i suppose it could be done with a cron  
or  
backgroundrb type deal where it compares the timestamp of the file and  
the  
current time and deletes the file after a certain amount of time has  
passed  
(probably have a mechanism to regen the reports anyway)…

any other issues i might need to look out for?

thanks in advance…

stuart (the other one)

---

<div class="post-metadata">

**Author:** ![Stuart\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9de053/32.png) [@Stuart\_W](https://www.ruby-forum.com/u/Stuart_W)\
**Post date:** [October 16, 2006, 3:20pm UTC](https://www.ruby-forum.com/t/generating-a-pdf-from-form-data-and-serving-it-back/72330/2 "2006-10-16T15:20:37Z")

</div>

On 10/16/06, Stuart W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> want to have a link created on the next page for the user to download the  
> pdf to their local machine. few questions: where’s the best place to store  
> the pdf in the rails tree (i imagine somewhere in public) for the user to be  
> able to download it.

It may not be a problem, but if you put the generated file into the  
public  
tree somewhere, then that file is available for anyone to download. If  
you  
store it outside your public tree you will need to serve it up with a  
controller action that utilises send\_data

also, since many users will be using this interface i need a mechanism  
to

> junk stale reports. i suppose it could be done with a cron or backgroundrb  
> type deal where it compares the timestamp of the file and the current time  
> and deletes the file after a certain amount of time has passed (probably  
> have a mechanism to regen the reports anyway)…

It may be possible for BackgroundDRB to look after this. If your  
controller  
passes the request to a background worker, the controller action may be  
able  
to clean up the file after download is complete. I’m not sure about  
this  
one though.

Maybe someone who has a better knowledge of BackgroundDRB would be able  
to  
answer this part better.

You can find BackgroundDRB at  
[http://brainspl.at/articles/tag/drb](http://brainspl.at/articles/tag/drb)

Hope that helps

---

<div class="post-metadata">

**Author:** ![Stuart\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9de053/32.png) [@Stuart\_W](https://www.ruby-forum.com/u/Stuart_W)\
**Post date:** [October 16, 2006, 6:21pm UTC](https://www.ruby-forum.com/t/generating-a-pdf-from-form-data-and-serving-it-back/72330/3 "2006-10-16T18:21:20Z")

</div>

Unless it would cause a big performance hit, you might want to think  
about not storing the PDFs at all. I have apps that generate CSV (for  
opening with a spreadhseet program) and do PDF form-filling on demand.  
It’s not a problem for me since those functions don’t get hit too  
frequently and what I’m generating isn’t more db or cpu-intensive than a  
typical CRUD webpage.

Stuart W. wrote:

> hey everybody,
> 
> this is unfortunately my second time typing this out since googlegroups  
> never posted my first message.
> 
> here’s my deal:
> 
> working on a rails app where the user fills in some form data and then  
> with  
> the given info i build a pdf with pdf-writer. after the pdf generates i  
> want  
> to have a link created on the next page for the user to download the pdf  
> to  
> their local machine. few questions: where’s the best place to store the  
> pdf  
> in the rails I tree (i imagine somewhere in public) for the user to be  
> able to  
> download it. also, since many users will be using this interface i need  
> a  
> mechanism to junk stale reports. i suppose it could be done with a cron  
> or  
> backgroundrb type deal where it compares the timestamp of the file and  
> the  
> current time and deletes the file after a certain amount of time has  
> passed  
> (probably have a mechanism to regen the reports anyway)…
> 
> any other issues i might need to look out for?
> 
> thanks in advance…
> 
> stuart (the other one)
