Whtmltopdf not working in PHP script

I would like to use wkhtmltopdf to convert HTML to PDF.

When I tried to convert it via linux terminal it works fine.

But when I tried with php script it doesn't work.

I am trying to execute binary directly.

here is the code i am trying to use from PHP.

exec('/home/binary_loc/wkhtmltopdf http://www.google.com /home/user/output.pdf');

      

My binary is located in the same folder where "index.php" exists.

I tried to get the version of the wkhtmltopdf binary from PHP, then returned the version.

But I can't figure out why it doesn't work to execute from php to pdf.

Here is the version checking code with php.

error_reporting(E_ALL);
ini_set('display_errors', '1');
$cmd = "./wkhtmltopdf --version";
$t = shell_exec($cmd);
echo $t;
exit()

      

Does anyone have a solution regarding this?

I want this because this will work on shared hosting too. There is no need to install wkhtmltopdf on the server.

+3


source to share


2 answers


Determine the full path to the wkhtmltopdf executable and the full path to the output folder.

To debug try something like this:



shell_exec("/home/binary_loc/wkhtmltopdf http://www.google.com /home/user/output.pdf > /home/user/debug.log 2>&1");

      

send error to file

0


source


Exec probably does not have permission to execute the file. PHP usually runs like apache

or nobody

, not your user account. You have to make sure that the execute bit is set for whatever user it is working with. You can use chmod 755 wkhtmltopdf

from its directory to provide read and execute to all users.



Please note that it is exec()

disabled on some shared hosting . Check with your host to make sure you have access to it.

0


source







All Articles