PDFkit不显示PDF图片 [英] PDFkit doesn't display pictures in PDF

查看:1227
本文介绍了PDFkit不显示PDF图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails 2,PDFkit 0.5.0

Rails 2, PDFkit 0.5.0

我使用PDFkit从Rails 2中的View生成PDF,一切正常.唯一不起作用的是在pdf中显示图片.

Im generating a PDF from a View in Rails 2 with PDFkit and everything works fine. The only thing which doesn't work is displaying pictures in the pdf.

当我在浏览器中查看视图"时,图片在那里,但在PDF中丢失. PDF中仅存在一个占位符.

When I look at the View in the Browser, the picture is there but its missing in the PDF. There is only a placeholder existing in the PDF.

image_tag看起来像这样:

The image_tag is looking like this:

<%= image_tag('plus.gif') %>

我也试图通过一个css文件来实现它,但是它也不起作用.

I also tried to realize it with a css-file but it doesn't work either.

有什么想法吗?

推荐答案

由于wkhtmltopdf的工作方式,您需要指定任何资产(JS,CSS,图像等),(包括域名.

Because of the way that wkhtmltopdf works you need to specify the full path to any assets (JS, CSS, images etc), including the domain name.

这行不通:

<img src="/images/foo.png" />

这将:

<img src="http://example.com/images/foo.png" />

一种解决方法是设置一个明确的资产宿主,即使它与您的应用程序在同一服务器上运行也一样(请参见

One workaround is to set an explicit asset host, even if it's the same server as your app is running on (see the AssetTagHelper documentation for details). Another would be to specify the hostname in the image_tag.

这篇关于PDFkit不显示PDF图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆