使用:
WKpdftohml版本0.12.3.2
PHPwkhtmltopdf版本2.2.0
chart.js之版本2.5.0Wkhtmltopdf不會呈現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添加
<div style="width:800px;height:200;font-size:10px;">
html標記 - 向圖表的JavaScript初始化添加了
ctx.canvas.width = 800;ctx.canvas.height = 200;
。
那麼毫無效果。我喜歡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
但不是我自己的?!
你試過只是關閉動畫? – Quince
我該怎麼做?我試過:''pdf - > setOptions(['orientation'=>'Landscape', 'javascript-delay'=> 500, //'window-status'=>'myrandomstring', 'animation'=> false, 'debug-javascript', 'no-stop-slow-scripts', ]);'但是它失敗了。 –