0

I am trying to create a PDF file from a HTML for which I am using npm html-pdf package. When I am trying to run this command from terminal

html-pdf ticket-2.html ticketpdf.pdf

its working fine and PDF is creating successfully.But when I am trying to run this command from a PHP file then its showing this error sh: html-pdf: command not found.

$ret = exec("html-pdf ticket-2.html ticketpdf.pdf", $out, $err);
print_r($out);

Output: Array ( [0] => sh: html-pdf: command not found )

Can anyone help me on this where this issue is exactly?

Thanks in advance

user2439124
  • 291
  • 1
  • 3
  • 16

1 Answers1

0

It seems your php script is not able to access the path where html-pdf is installed. For Windows, It will be installed in C:\Users\<username>\AppData\Roaming\npm assuming you would have installed it globally. Set this environment path in the scope of php script. It should work.

Edited: Try adding $_ENV["PATH"]="/home/designed/bin"; before $ret = exec("html-pdf ticket-2.html ticketpdf.pdf", $out, $err);

  • In my server I have globally installed html-pdf here : /home/designed/bin. Can you please help me how to set up environment variable? – user2439124 Aug 01 '19 at 10:44