After researching to see how I can make PHP know the orientation of the pdf, and found a solution with pdfinfo, it works fine by bash. but I can’t get that by PHP with executing exec command, I receive the response under the string to be able to create an if rule. I do not understand why the if of the PHP does not work with the answer of the ssh.
JavaScript
x
$test = shell_exec(' pdfinfo
-f 1
-l 1
sample.pdf
| grep "Page.* size:"
|
while read Page _pageno size _width x _height rest; do
[ "$(echo "${_width} / 1"|bc)" -gt "$(echo "${_height} / 1"|bc)" ]
&& echo "landscape"
|| echo "portrait" ;
done');
if($test=="portrait"){
echo "run script from portrait";
}else{
echo"run script from landscape";
}
Advertisement
Answer
There could be white space in the returned value. Use trim($test)
before the if
condition to trim the white space.