8

In my generated pdf I get this

0,00 €

instead of

0,00 €

Application.html.erb

  <meta charset="utf-8">
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />

show.html.erb

<%=number_to_currency item.total%>
sparkle
  • 7,530
  • 22
  • 69
  • 131

3 Answers3

24
respond_to do |format|
  format.html { render template: 'invoices/show' }
  format.pdf  do
    render pdf: 'invoices/show',
           template: 'invoices/show', 
           formats: :HTML, 
           encoding: 'utf8'
  end
end
Greg
  • 5,862
  • 1
  • 25
  • 52
sparkle
  • 7,530
  • 22
  • 69
  • 131
1

Still i can see the special characters in the PDF. Below is my code

pdf = WickedPdf.new.pdf_from_string(page_html,:page_size => "A3") 

  send_data(pdf, 
    :filename => "my_pdf_name.pdf", 
    :formats => 'HTML', 
    :encoding => 'utf8',
    :disposition => 'attachment') 
  end
Lokesh S
  • 426
  • 4
  • 13
  • I use this format.pdf do render pdf: "invoice", layout: 'layouts/metronic/blank.pdf', template: 'invoices/show', formats: :html, encoding: 'utf8' end – sparkle Apr 14 '21 at 12:47
  • Check for valid HTML doctype – sparkle Apr 14 '21 at 12:47
  • Yes, I am using the format as HTML and utf8 as encoding. Can you just tell, what's wrong with the above code snippet – Lokesh S Apr 15 '21 at 07:05
0

config/initializers/wicked_pdf.rb

  WickedPdf.config = {
    encoding: 'utf8'
  }
Jin Lim
  • 1,759
  • 20
  • 24