【发布时间】:2016-11-30 22:34:27
【问题描述】:
在 rails 4 中,我使用 wicked_pdf gem 来下载 .pdf 文件。我必须在这个 pdf 中添加一个图像,现在图像在开发中通过 wicked_pdf_image_tag 呈现,但在测试环境中图像(s3)没有呈现。
用过的宝石,
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 图像?
【问题讨论】:
标签: ruby-on-rails ruby pdf amazon-s3