Rails 4,如何将s3图像添加到邪恶的pdf [英] Rails 4, How to add an s3 image to wicked pdf
问题描述
在rails 4中,我正在使用wicked_pdf
gem来下载.pdf
文件.我必须在此pdf文件中添加一个图像,现在图像正在通过开发中的wicked_pdf_image_tag
呈现,但是在测试环境中,图像(s3)并未呈现.
In rails 4, I am using wicked_pdf
gem for .pdf
file download. I have to add an image inside this pdf, right now image is rendering through wicked_pdf_image_tag
in development but in test environment image(s3) is not rendering.
用过的宝石是,
gem 'wicked_pdf', '1.0.3'
gem 'wkhtmltopdf-binary', '0.9.9.3'
在初始化程序中,
class WickedPdf
wkhtmltopdf_path = Rails.env.production? ? "#{Rails.root}/bin/wkhtmltopdf-amd64" : "#{Rails.root}/bin/wkhtmltopdf-amd64"
WICKED_PDF = {
:exe_path => wkhtmltopdf_path,
:wkhtmltopdf => wkhtmltopdf_path
}
end
在控制器中,
respond_to do |format|
format.html {
render :pdf => "sample",
:margin => {:top => 10, :bottom => 10, :left => 10, :right => 10},
:orientation => 'Portrait', # default , Landscape,
:no_background => true
}
end
在视图中,我尝试加载
<%= Rails.env.development? ? wicked_pdf_image_tag("img/logo.png") : wicked_pdf_image_tag("#{Rails.root}/public/assets/img/logo.png") %>
<%= Rails.env.development? ? wicked_pdf_image_tag("img/logo.png") : wicked_pdf_image_tag("#{Rails.root}/assets/img/logo.png") %>
<%= image_tag(ActionController::Base.helpers.asset_path('img/logo.png')) %>
如何在PDF文件中加载s3
图片?
How can I load s3
image in pdf file?
推荐答案
您可以将图像放在s3存储桶中并公开.之后,请尝试如下操作.如果您使用以下代码,而无需在不同的环境中使用单独的语法,那么它将对所有环境都有效.希望如此.
You can put the image in a s3 bucket and make it public. After that try it like below. If you use the below code no need to use separate syntax for different environments, it will works for all .Hope it works.
<%= wicked_pdf_image_tag('//s3.amazonaws.com/bucket_name/image.png') %>
这篇关于Rails 4,如何将s3图像添加到邪恶的pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!