微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – 使用Wicked_PDF渲染为PDF时,ChartKick图表不会显示

我正在使用Rails 4,Wicked_PDF和Chartkick Gem
对于Google Charts,我使用:

<%= javascript_include_tag
“//www.google.com/jsapi”,“chartkik” %>

html视图提供了图表和所有预期的内容.
当我将.pdf附加到网址时,pdf文档会在浏览器中显示,但ChartKick图表不会显示.
图表应出现以下错误

Error Loading Chart: No adapter found

我在PDFKit文档中找到了以下内容.

Resources aren’t included in the PDF: Images,CSS,or JavaScript does
not seem to be downloading correctly in the PDF. This is due to the
fact that wkhtmltopdf does not kNow where to find those files. Make
sure you are using absolute paths (start with forward slash) to your
resources. If you are using PDFKit to generate PDFs from a raw HTML
source make sure you use complete paths (either file paths or urls
including the domain). In restrictive server environments the root_url
configuration may be what you are looking for change your asset host.

我假设wkhtmltopdf没有找到图表的链接,但我不知道如何解决这个问题.
有没有人有建议?

我找到了这个链接
Render jQuery in wicked_pdf

Unixmonkey帮助FattRyan为Highcharts解决这个问题.

任何人都可以帮助如何设置此wicked_pdf_javascript_include_tag,以便Wicket_PDF可以使用Google图表接受Chartkick的图表吗?

解决方法

在引用pdf布局中的CDN时,必须指定协议http或https.

此外,chartkick通过资产管道提供,因此请使用wicked_pdf_javascript_include_tag.

替换此行:

<%= javascript_include_tag "//www.google.com/jsapi","chartkik" %>

有了这个:

<%= javascript_include_tag "https://www.google.com/jsapi" %>
<%= wicked_pdf_javascript_include_tag "chartkick" %>

这就是我在我的一个项目中的表现.

干杯.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐