4

I use phpwkhtmltopdf as described here How do I get WKHTMLTOPDF to execute via 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: Uncaught exception 'Exception' with message 'Could not create PDF: Loading pages (1/6) [> ] 0% [======> ] 10% ' in /home/kpninfotech/public_html/pdfbin/convert.php:30 Stack trace: #0 {main} thrown in /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 get the same error

[> ] 0% [======> ] 10%

But the pdf conversion runs successfully when executed via ssh enter image description here

But i couldn't execute via PHP, How can i execute it via PHP?

I have VPS server running centos 6.5, wkhtmltopdf version 0.12.1 (with patched qt)

Community
  • 1
  • 1
Jagan K
  • 1,057
  • 3
  • 15
  • 38
  • Looks like your php user (apache / www / etc.) does not have write-permissions. You could change the ownership of the directory where you want to write to the php user. – jeroen Oct 07 '14 at 17:52
  • The server could able to create other files without errors http://kpninfotech.com/pdfbin/test1.php, executing the code from http://stackoverflow.com/questions/5560373/php-create-file-for-download-without-saving-on-server – Jagan K Oct 07 '14 at 18:06
  • Temporarily, change the permission of your file to 777 and see what happens. – shampoo Oct 07 '14 at 19:46
  • This is definitely a problem with your PHP configuration, I got this resolved when I upgraded to a better VPS server. If you have WHM access go & set this package to use unlimited resource. It may fix it – Jagan K Jan 25 '15 at 04:37

1 Answers1

0

I solved this exaticly problem setting options disable-javascript.

Try this.

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());
}
fnandogp
  • 51
  • 3