使用Wicked_PDF呈现为PDF时,ChartKick图表不显示 [英] ChartKick charts do not show when rendering to PDF using Wicked_PDF

查看:725
本文介绍了使用Wicked_PDF呈现为PDF时,ChartKick图表不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Rails 4,Wicked_PDF和Chartkick Gem的

对于Google Charts,我使用:


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


提出了图表和一切如预期。
当我将.pdf附加到网址时,pdf文档在浏览器中显示,但ChartKick图表不显示。

图表应出现以下错误:


加载图表时出错:找不到适配器


在PDFKit文档中在线。


资源不包括在PDF中:图像,CSS或JavaScript
不似乎在PDF中正确下载。这是由于
的事实,wkhtmltopdf不知道在哪里找到这些文件。 make
确保您使用绝对路径(以正斜杠开头)到
资源。如果您使用PDFKit从原始HTML
源生成PDF,请确保使用完整的路径(文件路径或包含域的
的url)。在限制性服务器环境中,root_url
配置可能是您正在寻找的更改资产主机。


wkhtmltopdf找不到图表的链接,但我不知道如何解决这个问题。

有没有人有建议?



我找到此链接:

在wicked_pdf中渲染jQuery



其中Unixmonkey帮助FattRyan为Highcharts解决这个问题。



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

解决方案

您必须在引用时指定协议 http https

还通过资产管道提供了chartkick ,所以使用 wicked_pdf_javascript_include_tag



  

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

有了这个:

 <%= javascript_include_taghttps://www.google.com/jsapi%> 
<%= wicked_pdf_javascript_include_tagchartkick%>

这是我在一个项目中的做法。



干杯。


I am using Rails 4, Wicked_PDF and Chartkick Gem's
For Google Charts I use:

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

The html view comes up with charts and everything as expected. When I append .pdf to the url the pdf document shows in the browser but the ChartKick charts do not show.
The following error appears where the chart should be:

Error Loading Chart: No adapter found

I have found the following online in the PDFKit documentation.

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.

I am assuming that wkhtmltopdf is not finding the link to the charts, but I am not sure how to fix this.
Does anyone have a suggestion?

I found this link:
Render jQuery in wicked_pdf

Where Unixmonkey helps FattRyan to solve this for Highcharts.

Can anyone help how to set this wicked_pdf_javascript_include_tag so that Wicket_PDF will accept charts from Chartkick using Google charts?

解决方案

You have to specify a protocol http or https when referencing to a CDN inside the pdf layout.

Also chartkick is served via the assets pipeline, so use wicked_pdf_javascript_include_tag instead.

Replace this line:

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

With this:

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

That's how I do it in a project of mine.

Cheers.

这篇关于使用Wicked_PDF呈现为PDF时,ChartKick图表不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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