I actually generate PDF with WickedPDF on my app. And now I just want to include an image "logo.jpg" on the header of my PDF.
I tried lot of things, and I think my problem come from assets.
My Controller :
def generate_pdf
pdf = WickedPdf.new.pdf_from_string(
render_to_string(
template: 'pdf/pdf_view.pdf.erb',
layout: 'layouts/application.pdf.erb'))
send_data(pdf,
filename: 'file_name.pdf',
type: 'application/pdf',
disposition: 'attachment')
end
layouts/application.pdf.erb :
<!doctype html>
<html>
<head>
<meta charset='utf-8' />
</head>
<body onload='number_pages'>
<div id="content">
<%= yield %>
</div>
</body>
</html>
pdf/pdf_view.pdf.erb :
<div>
<p>Just a simple text on my pdf that is correctly displayed</p>
<%= wicked_pdf_image_tag "images/logo.jpg", :width=>"250", :height=>"200" %>
</div>
And in my console :
Rendering pdf/pdf_view.pdf.erb within layouts/application.pdf.erb
Rendered pdf/pdf_view.pdf.erb within layouts/application.pdf.erb (2.7ms)
[wicked_pdf]: ["/home/vincent/.rvm/gems/ruby-2.7.1/bin/wkhtmltopdf", "file:////tmp/wicked_pdf20210503-14279-o2q5ol.html", "/tmp/wicked_pdf_generated_file20210503-14279-1om4oam.pdf"]
source=rack-timeout id=cfb572c3-5919-47c1-b32c-cc3bf724b9bf timeout=15000ms service=1000ms state=active
Rendering text template
Rendered text template (0.1ms)
Sent data file_name.pdf (1.5ms)
Completed 200 OK in 1140ms (Views: 1.1ms | ActiveRecord: 1.1ms)
So my question is : Do you have an other method to display an image on a generated pdf ? Or is my method wrong ?