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" %>

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

干杯.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...