Reputation: 2940
I'm trying to render an email to a pdf file using the wicked_pdf gem inside a rails 4 application.
Is such an operation possible? I tried
ApplicationController.new.render_to_string :text => email.body, :format => :pdf, :template => 'wicked_pdf/template', :layout => 'wicked_pdf'
but that yields an empty string. Note that even though the templates should not be used, I created them as they are needed by render to work.
email.body
can be replaced with any string to the same result.
Both files are empty with only a <%= yield %>
.
Upvotes: 1
Views: 180
Reputation: 2940
I inferred the right solution from rii's answer:
If you already have a string or html text, you can render it as a pdf by simply calling
pdf = WickedPdf.new.pdf_from_string(email.body)
there is no need to call any render. So you don't need any template or anything.
Upvotes: 0
Reputation: 1648
From the Wicked PDF documentation:
The wkhtmltopdf binary is run outside of your Rails application; therefore, your normal layouts will not work. If you plan to use any CSS, Javascript, or image files, you must modify your layout so that you provide an absolute reference to these files.
This is how I normally render wicked PDF files.
pdf = WickedPdf.new.pdf_from_string(
ActionController::Base.new().render_to_string(:template => YourTemplate, :locals => {:something => @something})
)
Hope that helps.
Upvotes: 1