Prawn表格中的欧元符号未显示出来。

3

我在rails中遇到了一个问题,无法在prawn表格中显示欧元符号。我使用prawn为用户提供下载pdf发票的可能性。

pdf = Prawn::Document.new
[...]

invoice_data = [["Description", "Price", "Qty", "Total"]]

invoice_items.map do |item|
  pdf.font "#{Prawn::BASEDIR}/data/fonts/verdanab.ttf"
  pdf.font "#{Prawn::BASEDIR}/data/fonts/Verdana.ttf"
  invoice_data << ["","€ 10",1,"€ 10"]
end


pdf.table(invoice_data, :width => pdf.bounds.width,:cell_style => { :inline_format => true },:row_colors => ["FFFFFF", "DDDDDD"])

问题是在我尝试运行这段代码后,我收到了这个错误,否则我无法使其工作...

invoices_pdf.rb:64: invalid multibyte char (US-ASCII)
invoices_pdf.rb:64: invalid multibyte char (US-ASCII)
invoices_pdf.rb:64: syntax error, unexpected $end, expecting ']'
  invoice_data << ["","€ 10",1,"€ 10"]
                         ^

我在虾群组看到了一些有关pdf.text元素的提示,但这是一个表格,我无法弄清楚......谢谢!
1个回答

6

为了帮助其他人。

我在prawn google组中得到了来自"James Healy"的答案:

To include non-ascii characters in a ruby 1.9 file you must add the following to the first line of the file:

# coding: utf-8

Cheers

James

没想到啊。

谢谢。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接