[英]Node js html-pdf command not working from PHP
I am trying to create a PDF file from a HTML for which I am using npm html-pdf package. 我正在尝试从使用npm html-pdf软件包的HTML创建PDF文件。 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. 它的工作正常,PDF创建成功。但是,当我尝试从PHP文件运行此命令时,则显示此错误sh:html-pdf:命令未找到。
$ret = exec("html-pdf ticket-2.html ticketpdf.pdf", $out, $err);
print_r($out);
Output: Array ( [0] => sh: html-pdf: command not found ) 输出:数组([0] => sh:html-pdf:找不到命令)
Can anyone help me on this where this issue is exactly? 谁能帮我解决这个问题所在?
Thanks in advance 提前致谢
It seems your php script is not able to access the path where html-pdf
is installed. 看来您的php脚本无法访问
html-pdf
的安装路径。 For Windows, It will be installed in C:\\Users\\<username>\\AppData\\Roaming\\npm
assuming you would have installed it globally. 对于Windows,假定您已全局安装,它将安装在
C:\\Users\\<username>\\AppData\\Roaming\\npm
。 Set this environment path in the scope of php script. 在php脚本范围内设置此环境路径。 It should work.
它应该工作。
Edited: Try adding $_ENV["PATH"]="/home/designed/bin";
编辑:尝试添加
$_ENV["PATH"]="/home/designed/bin";
before $ret = exec("html-pdf ticket-2.html ticketpdf.pdf", $out, $err);
$ret = exec("html-pdf ticket-2.html ticketpdf.pdf", $out, $err);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.