![](/img/trans.png)
[英]rake test and error : log writing failed. “\xE2” from ASCII-8BIT to UTF-8
[英]Failed to execute: Error: “\xFE” from ASCII-8BIT to UTF-8
Rails 4 * Mac OSX 10.8.4 *
我正在使用以下Gem來生成wicked_pdf pdf:
gem 'wkhtmltopdf-binary'
gem 'wicked_pdf'
渲染視圖作為pdf工作正常,谷歌正確顯示它的PDF查看器。 我的PDF看起來就像我想要的那樣。
當我嘗試將pdf保存到光盤時,問題就出現了,目的是通過電子郵件將它們發送給用戶。
例如,這工作正常:
def command
@event = Event.find(params[:id])
@client = Contact.find(@event.client_id)
@organizer = Contact.find(@event.organizer_id)
render layout: 'command',
pdf: 'Event Command',
show_as_html: params[:debug].present?,
dpi: 300,
print_media_type: true,
margin: {
top: 0,
bottom: 0,
left: 0,
right: 0
}
end
這將在Google Chrome PDF查看器中呈現pdf。
但在這里,我想生成PDF並保存到文件。
def send_email
@event = Event.find(params[:id])
@client = Contact.find(@event.client_id)
@organizer = Contact.find(@event.organizer_id)
proforma = render_to_string(
pdf: 'proforma.pdf',
template: 'events/proforma',
layout: 'proforma'
)
pdf = WickedPdf.new.pdf_from_string(
proforma
)
save_path = Rails.root.join('public','proforma.pdf')
File.open(save_path, 'wb') do |file|
file << pdf
end
end
但是我收到了錯誤:
Failed to execute:
Error: "\xFE" from ASCII-8BIT to UTF-8
試試這個:
File.open(save_path, 'w:ASCII-8BIT') do |file|
file << pdf
end
在內存中呈現為字符串的PDF似乎是ASCII格式,因此請將其保存為:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.