8

I'm using PDFKit in my Rails app to generate PDF's. Problem is some of my content in contains non-ascii characters. How do I force it to use UTF-8?

tybro0103
  • 48,327
  • 33
  • 144
  • 170

2 Answers2

15

Fixed by adding this to in the html head:

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
tybro0103
  • 48,327
  • 33
  • 144
  • 170
3
You can write in PDFKIT configration.

 PDFKit.configure do |config|
        config.wkhtmltopdf = '/opt/wkhtmltopdf'
        config.default_options = {
          :encoding      => 'UTF-8'
          :page_size     => 'Letter',
          :margin_top    => '0.3in',          
          :margin_bottom => '0.1in',          
          :print_media_type => true                       
        }
 end
Govind shaw
  • 407
  • 4
  • 12
  • can you please add link to the docs that explain how to do that ? – ddor254 Apr 11 '19 at 08:44
  • I have written above in config/initializers/pdfkit.rb file (ROR App). And It is working fine for me. I did this by using https://github.com/mileszs/wicked_pdf document – Govind shaw Apr 12 '19 at 09:47
  • Please check https://stackoverflow.com/questions/55329282/how-to-load-images-precompiled-assets-with-pdfkit-wkhtmltopdf-rails-5-2 – Govind shaw Apr 12 '19 at 10:03
  • `utf-8` is the default value for `encoding` key anyway https://github.com/pdfkit/pdfkit/blob/master/lib/pdfkit/configuration.rb#L19 – Artur INTECH Oct 15 '19 at 16:12