使用:
WKpdftohml 版本 0.12.3.2
PHPwkhtmltopdf 版本 2.2.0
Chart.JS 版本 2.5.0
我正在尝试使用上述库打印折线图。我可以使用 shell 命令重现 pdf:wkhtmltopdf --javascript-delay 5000 " http://netdna.webdesignerdepot.com/uploads7/easily-create-stunning-animated-charts-with-chart-js/chartjs-demo.html" test2.pdf
所以 WKhtmltopdf 没有问题。
问题是当我在我的应用程序中使用 PHPwkhtmltopdf 库执行此操作时。我得到一个空白页。
根据我的研究,这些是我尝试过的事情:
- 添加
'javascript-delay' => 500
到 Chart.JS 选项; - 添加
animation:{onComplete: function () {window.JSREPORT_READY_TO_START =true}
到 Chart.JS 选项; - 添加
<div style="width:800px;height:200;font-size:10px;">
到canvas html标签的父div - 添加
ctx.canvas.width = 800;ctx.canvas.height = 200;
到图表的 javascript 初始化中。
好吧,没有任何效果。我喜欢 Chart.JS 和 WKhtmltopdf,但如果我无法打印,我将不得不放弃其中一个。有什么解决办法吗?
这是我的 PHPwkhtmltopdf 的 php 代码:
public function imprimir ($request, $response)
{
// include_once 'config/constants.php';
// include_once 'resources/auxiliar/helpers.php';
$folha = $_POST['printit'];
$variaveis = explode(',', $folha);
$nomeFicheiro = $variaveis[0];
$printName = substr($nomeFicheiro, 5);
if (isset($variaveis[2])) {
$_SESSION['mesNumero'] = $variaveis[2];
$_SESSION['mes'] = $variaveis[1];
} else {
$mesNumero = 0;
$mes = '';
}
ob_start();
if ($nomeFicheiro == 'printPpiam') {
require ('C:/xampp/htdocs/.../'.$nomeFicheiro.'.php');
} else {
require ('C:/xampp/htdocs/.../'.$nomeFicheiro.'.php');
}
$content = ob_get_clean();
// You can pass a filename, a HTML string, an URL or an options array to the constructor
$pdf = new Pdf($content);
// On some systems you may have to set the path to the wkhtmltopdf executable
$pdf->binary = 'C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf';
$pdf -> setOptions(['orientation' => 'Landscape',
'javascript-delay' => 500,
// 'enable-javascript' => true,
// 'no-stop-slow-scripts' => true]
]);
if (!$pdf->send($printName.'.pdf')) {
throw new Exception('Could not create PDF: '.$pdf->getError());
}
$pdf->send($printName.'.pdf');
}
# 更新 1
用页面输出制作了一个 php 文件。在浏览器中运行它并呈现图形。当我在控制台中执行此操作时,它会呈现除图形之外的所有内容!
wkhtmltopdf怎么会渲染这个页面中的图形:http://netdna.webdesignerdepot.com/uploads7/easily-create-stunning-animated-charts-with-chart-js/chartjs-demo.html
但不是我自己的?!