This is my code:
$url = escapeshellarg("http://www.mysite.com");
$command = shell_exec("xvfb-run -a -s '-screen 0 640x480x16' wkhtmltopdf --dpi 300 --page-size A4 $url /srv/www/mysite/public_html/tmp_pdf.pdf");
$str = file_get_contents("/srv/www/mysite/public_html/tmp_pdf.pdf");
header('Content-Type: application/pdf');
header('Content-Length: '.strlen($str));
header('Content-Disposition: inline; filename="pdf.pdf"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression','0');
die($str);
In my bash shell (using Debian) the command
shell_exec(“xvfb-run -a -s ‘-screen 0 640x480x16’ wkhtmltopdf –dpi
300 –page-size A4 html://www.mysite.com /srv/www/mysite/public_html/tmp_pdf.pdf
works and it generates a pdf in the desired location but when i excecute the command in php nothing gets created and i’m returned to a null pdf file (because it doesn’t exist).
Can someone help me figure what is wrong?
The problem was that Apache server doesn’t have write access to the folder i’ve tried to write the pdf into (which is /srv/www/mysite/public_html/ in my example).
So i simply changed the folder location to /tmp (where everyone has write permissions) and now it works. The corrected code is: