lundi 26 novembre 2018

How to generate pdf using 'wkhtmltopdf-binary' in rails 3.22

I have account datatable for which i need to generate pdf.
However i used

gem 'wkhtmltopdf-binary'

But iam getting reponse of generated pdf only once.i.e I cannot render the attachment view after clicking print button.

Here is my controller code:

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 


And My view with 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>


Can anyone help me on generating PDF attachment?

Aucun commentaire:

Enregistrer un commentaire