Wkhtmltopdf hangs at 10% when executed via PHP, but is successfully launched via command line
I am using phpwkhtmltopdf as described here How do I get WKHTMLTOPDF to execute through PHP?
to convert html to pdf
set_time_limit (0);
require_once __DIR__.'/vendor/autoload.php';
use mikehaertl\wkhtmlto\Pdf;
$pdf = new Pdf;
$pdf->addPage('<html><h1>PDF creation successfull</h1></html>');
$pdf->send('test.pdf');
if (!$pdf->send('test.pdf')) {
throw new Exception('Could not create PDF: '.$pdf->getError());
}
when i run this i get the following error:
Fatal error: Throw an exception "Exception" with the message "Failed to create PDF: Loading pages (1/6) [>] 0% [====== →] 10% 'in / home / kpninfotech / public _html / pdfbin /convert.php:30 Stack trace: # 0 {main} to / home / kpninfotech / public _html / pdfbin / convert.php on line 30
I also tried to run exec command from php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$cmd = "/usr/bin/wkhtmltopdf http://www.kpninfotech.com test.pdf 2>&1";
echo $t = exec($cmd);
exit();
Here also I am getting the same error
[>] 0% [====== →] 10%
But PDF conversion succeeds when done via ssh
But I couldn't execute via PHP, how can I execute it via PHP?
I have a VPS server running centos 6.5, wkhtmltopdf version 0.12.1 (with qt fixed)
source to share
I solved this option to exaticly disable-javascript setting.
Try it.
use mikehaertl\wkhtmlto\Pdf;
$pdf = new Pdf(array('disable-javascript'));
$pdf->addPage('<html><h1>PDF creation successfull</h1></html>');
$pdf->send('test.pdf');
if (!$pdf->send('test.pdf')) {
throw new Exception('Could not create PDF: '.$pdf->getError());
}
source to share