# Need urgent help!

**URL:** <https://www.ruby-forum.com/t/need-urgent-help/131921>\
**Category:** Rails\
**Created:** [March 14, 2008, 1:09pm UTC](https://www.ruby-forum.com/t/need-urgent-help/131921 "2008-03-14T13:09:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@ajay](https://www.ruby-forum.com/u/ajay)\
**Post date:** [March 14, 2008, 1:09pm UTC](https://www.ruby-forum.com/t/need-urgent-help/131921/1 "2008-03-14T13:09:53Z")

</div>

How to load pdf file in browser using rails and how to store it in  
MySQL database using same?

---

<div class="post-metadata">

**Author:** ![ajay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@ajay](https://www.ruby-forum.com/u/ajay)\
**Post date:** [March 14, 2008, 1:45pm UTC](https://www.ruby-forum.com/t/need-urgent-help/131921/2 "2008-03-14T13:45:14Z")

</div>

Ajay wrote:

> How to load pdf file in browser using rails and how to store it in  
> MySQL database using same?

I use PDFWriter to generate PDF reports, and the controller for a model  
handles the call for creation by the model and routing it to the users  
browser, like this (mode is a param value that tells the model if the  
user requested the long or short form of the report, the renderOnPdf is  
the model method to gen the pdf, construct a filename for the PDF, and  
send\_data send it to the user):

def pdf  
@project = Project.find(params[:id])  
mode = params[:mode]

```
pdf = PDF::Writer.new
pdf.start_page_numbering(300, 20, 10, :center, nil, nil)

@project.renderOnPdf( mode, "no", pdf )

pdf.stop_page_numbering( true, :current )
x_now = Time.now
x_filename = 

```

@project.projname+"-"+x\_now.strftime("%Y-%m-%d-%H%M")+".pdf"  
send\_data pdf.render, :filename =\> x\_filename, :type =\>  
“application/pdf”  
end

I don’t store my PDFs in the database, but I assume it’d just be a blob.

---

<div class="post-metadata">

**Author:** ![ajay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@ajay](https://www.ruby-forum.com/u/ajay)\
**Post date:** [March 14, 2008, 2:08pm UTC](https://www.ruby-forum.com/t/need-urgent-help/131921/3 "2008-03-14T14:08:10Z")

</div>

If you’re asking about how to let the user select a PDF document from  
their system and send it to the app server, then look into  
attachment\_fu.
