how to generate pdf using wicked pdf gem.

This article is gives basic knowledge about how generate pdf using wicked_pdf gem in ruby on rails. Follow these steps for pdf generation

Add these gems in Gemfile file
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
Run these commands in console to install wicked_pdf package
bundle install
Run these commands in console to create wicked_pdf.rb file
rails generate wicked_pdf
Run this command in console for wkhtmltopdf path and put it in wicked_pdf.rb file
which wkhtmltopdf
Put this code in sample.html.erb file
link_to "Save", {:controller => "home", :action => "pdf"}, :class => "font-bold underline", :id=>"save",  :title=>"Save"
      
Put this code in routes.rb file
get '/home/pdf' => 'home#pdf'
Put this code in sample_controller.rb file
def pdf
   render pdf: 'converter_result',
   disposition: 'attachment',
   template: 'home/pdf',
   page_size: nil,
   zoom: 0.6,
   :save_as_html => true
end
Put this code in pdf.html.erb file
<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    put pdf content here
  </body>
</html>
Note: If pdf content is not shown properly for other language. For example: spanish language
scenario:
Wicked pdf before
You can add this code in pdf.html.erb file for the solution
<!DOCTYPE html>
<html>
  <head>
    <meta charset='UTF-8'>
  </head>
  <body>
    put pdf content here
   </body>
</html>
Wicked pdf after