igor-alexandrov / wisepdf

Wkhtmltopdf wrapper done right
MIT License
281 stars 20 forks source link

How to render a pdf from object returned from Writer.new #20

Closed jersinghaus closed 10 years ago

jersinghaus commented 10 years ago

Hello,

Forgive me as this is not really an issue, but I store html in a database and am using wisepdf to convert to pdf format. But I don't know how to render the pdf back to the browser.

I'm doing something like this in my controller:

def index respond_to do |format| format.pdf do my_pdf = PdfTable.find_by_code('my_pdf') pdf = Wisepdf::Writer.new.to_pdf(my_pdf) send_data pdf, type: 'application/pdf', disposition: 'inline' end end end

But my tab opened in ff (using pdf ff addon) is blank.

How would I render the string pdf returned from Writer.new?

Thanks

igor-alexandrov commented 10 years ago

Hmm, maybe you are missing something here:

template = PdfTable.find_by_code('my_pdf')
pdf = Wisepdf::Writer.new.to_pdf(template.content)

I mean, that you forget to pass some attribute from your PdfTable instance object to Wisepdf::Writer.new.to_pdf.

jersinghaus commented 10 years ago

Yep, sorry, I'm an idiot. I was overwriting the 'template' variable. Doh!

Thanks for the quick reply though! :)