我有需要为其生成pdf的帐户数据表。
但是我用
gem'wkhtmltopdf-binary'
但是我只收到一次生成的pdf响应,即单击“打印”按钮后无法渲染附件视图。
这是我的控制器代码:
def acclose_pdf
@hp = HpEntry.where(:HPEntryId => params[:hp_id]).last
@test_ac = @hp.Name
html_content = render_to_string(:action=>"acclose_pdf.html.erb",:layout=> false)
pdf_convert = PDFKit.new(html_content,:margin_right => '0.2in',:margin_left => '0.2in',:margin_top => '0.2in',:margin_bottom => "0.1in",:page_size => "A4", :orientation => 'landscape')
send_data(pdf_convert.to_pdf,:filename=>"ClosedAccount.pdf", :disposition => "Attachment")
end
我对Ajax的看法:
<%= button_tag "Print" ,:class =>'btn btn-success print_ac_close_data',:id => "#{entry.HPEntryId}"%>
<script type="text/javascript">
$('.print_ac_close_data').click(function(){
var hp_id = $(this).attr('id')
var class_val = $(this).val()
$.ajax({
dataType: "html",
cache: false,
url: "/ac_close_print",
data: {"hp_id": hp_id},
contentType: "application/json",
});});</script>
谁能帮我生成PDF附件?