1

Same as question, I would like to generate a PDF document with some content from database. And automatically attach it to an email to users. Do you think gem like WickedPDF or Prawn can achieve that?

Edit I have a Heroku Setup, does it affect my ability to use WickedPDF and WKpdf2html?

Chris Yeung
  • 2,613
  • 6
  • 34
  • 57

2 Answers2

3

You can generate pdf from html also and attach that to your mail using PDFKit

here are codes inside your controller

  html=render_to_string(:partial=> "confirmation")
  pdfkit_instance = PDFKit.new(html)  
  UserMailer.registration_confirmation(@user,pdfkit_instance.to_pdf).deliver

in your mailer class use the following

def registration_confirmation(user,pdf_file)
    attachments["#{user.company_name}_#{Time.now.strftime("%m%d_%Y")}.pdf"] =pdf_file
    mail(:to => "#{user.name} <#{user.email}>", :subject => "yoursubject " 
end

For installing PDFKit you can go through the blog http://blog.andolasoft.com/2012/10/usage-of-pdfkit-with-rails-328-and-ruby.html

1

Yes, they can generate pdf files in your tmp dir (or wherever you like) and then you can use these files as attachments.

thorsten müller
  • 5,621
  • 1
  • 22
  • 30
  • http://stackoverflow.com/questions/12294781/prawn-pdf-attachments-in-the-email / http://stackoverflow.com/questions/9467989/rails-3-render-prawn-pdf-in-actionmailer – thorsten müller Feb 19 '14 at 11:36
  • It seems to me that WickedPDF is simpler but can because it uses WKhtmlpdf, can I use it if I have a Heroku set up? – Chris Yeung Feb 19 '14 at 12:04
  • I don't know in the context of Heroku. It has some limitations since it converts html to pdf (which has the advantage that you can use normal view code to generate it). I only have experience with Prawn, it's a bit nasty sometimes but not that complicated after all. – thorsten müller Feb 19 '14 at 12:08