我想要一份记录中有图像的PDF报告。
html报告使用以下代码运行良好:
<% if @student.photo.file? %>
<%= image_tag @student.photo.url %>
<% end %>
但当我尝试使用以下代码的pdf报告时,它不起作用。请帮忙。
<% if @student.photo.file? %>
<%= wicked_pdf_image_tag @student.photo.url %>
<% end %>
这是我在控制器中的def
def generate_id_card
@student = Student.find(params[:id])
render :pdf=>'generate_id_card',
:show_as_html => true
which wkhtmltopdf
没有显示任何内容,但我已将其安装在/opt
目录中:/opt/wkhtmltopdf-amd64
WickedPdf.config是
WickedPdf.config = {
# :wkhtmltopdf => '/opt/wkhtmltopdf',
:wkhtmltopdf => '/opt/wkhtmltopdf-amd64',
:layout => "pdf.html",
:margin => { :top=> 40,
:bottom => 20,
:left=> 30,
:right => 30},
:header => {:html => { :template=> 'layouts/pdf_header.html'}},
:footer => {:html => { :template=> 'layouts/pdf_footer.html'}}
哪些工作什么都不显示,但我在/opt中安装了它/opt/wkhtmltopdf-amd64
WickedPdf.config是
WickedPdf.config = {
# :wkhtmltopdf => '/opt/wkhtmltopdf',
:wkhtmltopdf => '/opt/wkhtmltopdf-amd64',
:layout => "pdf.html",
:margin => { :top=> 40,
:bottom => 20,
:left=> 30,
:right => 30},
:header => {:html => { :template=> 'layouts/pdf_header.html'}},
:footer => {:html => { :template=> 'layouts/pdf_footer.html'}}
rendered_id_card = render_to_string(:template => "students/generate_id_card.pdf.erb", :show_as_html => true )
pdf = WickedPdf.new.pdf_from_string rendered_id_card
试试这个