How to load pdf file in browser using rails and how to store it in
MySQL database using same?
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.
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.