简体   繁体   English

wkhtmltopdf - 将AJAX创建的SVG转换为PDF

[英]wkhtmltopdf - Converting SVG created by AJAX to PDF

I am working on an application that converts HTML and SVG charts, generated with d3.js, to PDF. 我正在开发一个应用程序,将使用d3.js生成的HTML和SVG图表转换为PDF。 The charts are rendered through AJAX calls after the page loads. 页面加载后,图表将通过AJAX调用呈现。

I am working with wkhtmltopdf 0.9.6 which seems to do a great job converting static HTML5 to PDF, but I am having problems converting the SVG charts. 我正在使用wkhtmltopdf 0.9.6,这似乎很好地将静态HTML5转换为PDF,但我在转换SVG图表时遇到了问题。

When rendering a simple multi series line chart, most of the chart area is not rendered. 渲染简单的多系列折线图时,不会渲染大部分图表区域。 Even after disabling animations. 即使在禁用动画后也是如此。 Using the --redirect-delay doesn't help even when set to 8000. 使用--redirect-delay即使设置为8000也无济于事。

What's interesting is that most that parts of the chart are rendered, like the legend and axis. 有趣的是,图表的大多数部分都被渲染,如图例和轴。 Just not the content. 只是没有内容。

Anyone else encountered this or a similar problem? 其他人遇到过这个或类似的问题?

Thank you. 谢谢。

If you are using wkhtmltopdf in shell, as an alternative to setting a timer in your source, you can add this option: 如果您在shell中使用wkhtmltopdf,作为在源中设置计时器的替代方法,您可以添加以下选项:

--javascript-delay 30000

For instance, a complete command might look like this: 例如,完整的命令可能如下所示:

wkhtmltopdf --enable-javascript --debug-javascript --javascript-delay 30000 --images http://www.google.com google.pdf

add last page this script: 添加最后一页这个脚本:

function sleep(milliSeconds) {
    var startTime = new Date().getTime(); // get the current time
    while (new Date().getTime() < startTime + milliSeconds); // hog cpu
}

sleep(5000);

And: --redirect-delay -> 5000 并且: - redirect-delay - > 5000

Use library d3.js no compress other js. 使用库d3.js不压缩其他js。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM