我想生成一个PDF与我们的部门标志在它。当我尝试在控制器中使用WickedPdf类时(使用https://github.com/mileszs/wicked_pdf中描述的方法):
def some_action
image_tag_string = image_tag('logo.jpg')
pdf = WickedPdf.new.pdf_from_string(image_tag_string)
save_path = Rails.root.join('testpdfs','logotest.pdf')
File.open(save_path, 'wb') do |file|
file << pdf
end
end...the应用程序将PDF保存到目标目录,但它有一个蓝白相间的'?‘标记图像应该在的位置。
如果我这样做:
image_tag_string = wicked_pdf_image_tag('logo.jpg')
pdf = WickedPdf.new.pdf_from_string(image_tag_string)我得到以下错误:
NoMethodError:
undefined method `wicked_pdf_image_tag' for #<...似乎我的Rails应用程序也缺少/没有链接到属于wicked-pdf gem的帮助文件。
对StackOverflow上类似问题的回答建议编写一个自定义的" image -tag“助手来定位镜像或安装wkhtmltopdf。对我来说,当放置在视图(whatever.html.erb)中时,image-tag可以很好地显示徽标。"logo.jpg“已经位于资产管道和#{RailsRoot}/public/RailsRoot中。最后,我在Ubuntu 14.04上使用wkhtmltopdf 0.9.9、wicked-pdf 0.11.0和Rails4。
简而言之--我做错了什么,导致WickedPDF无法渲染图像?
发布于 2015-05-09 14:48:38
首先创建一个pdf模板来呈现并在该模板中使用wicked_pdf标记。例如:
app/views/layout/application.pdf.erb-
<!doctype html>
<html>
<head>
<meta charset='utf-8' />
</head>
<body onload='number_pages'>
<div id="content">
<%= yield %>
</div>
</body>
</html>app/views/pdf/pdf_view.pdf.erb-
<div>
<%= wicked_pdf_image_tag 'logo.jpg' %>
</div>请改用此模板
def save
pdf = WickedPdf.new.pdf_from_string(
render_to_string(
template: 'example/pdf_view.pdf.erb',
layout: 'layouts/application.pdf.erb'))
send_data(pdf,
filename: 'file_name.pdf',
type: 'application/pdf',
disposition: 'attachment')
end这可能对你有帮助..。
发布于 2021-09-05 01:16:04
在视图中使用wicked_pdf_image_tag帮助器,如果图像为public/images格式,则使用asset_url引用图像;如果图像为public/packs/media/images格式,则使用asset_pack_url引用图像
<%= wicked_pdf_image_tag asset_url('/images/footer_logo.png') %>或
<%= wicked_pdf_image_tag asset_pack_url('media/images/footer_logo.png') %>发布于 2019-02-14 03:30:41
我转换的图像网址是'http‘从'https’。而不是工作。
Heroku-18
Rails 4.2
wicked_pdf (1.1.0)
wkhtmltopdf-binary (0.12.4)https://stackoverflow.com/questions/30110344
复制相似问题