I cannot get wicked_pdf to display an image from active storage to a pdf file.
Do I use: wicked_pdf_image_tag
or wicked_pdf_asset_base64
or just image_tag
in the pdf template. Then do I give a rails_blob_path(company.logo)
or just company.logo
to any other method?
There is some ongoing work to add Active Storage support to wicked_pdf
in this GitHub issue thread
Until that is added (you can help!), you can create a helper method something like this (which is a slightly modified version of an example from the thread above):
# Use like `image_tag(wicked_active_storage_asset(user.avatar))`
def wicked_active_storage_asset(asset)
return unless asset.respond_to?(:blob)
save_path = Rails.root.join('tmp', asset.id.to_s)
File.open(save_path, 'wb') do |file|
file << asset.blob.download
end
save_path.to_s
end
Or, if you can use web resources directly in your PDF creation process:
<img src="<%= @user.avatar.service_url %>">
<img src="<%= @user.avatar.variant(resize: "590").processed.service_url %>">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With