7

How I can execute those two command line via php:

wkhtmltopdf www.google.com gg.pdf

&

oofice -headless -nologo -pt cup-pdf my.doc

they both return a pdf file and download into my home directory.

I want to know the way to execute those command from my html page via php.

Thanks.

Simen Echholt
  • 11,243
  • 2
  • 34
  • 26
XS07
  • 71
  • 1
  • 1
  • 3
  • See [This](http://stackoverflow.com/questions/566248/cant-execute-php-script-using-php-exec) – Iman Jul 22 '11 at 22:14

2 Answers2

15

You should take a look at the System program execution section of the manual : PHP provides several functions that can be used to launch external commands / programs, including :

  • exec() -- which can store the output of the command in an array
  • shell_exec() -- which returns, as a string, the output of the command
  • system() -- which echoes the output of the command
Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
  • Thanks Pascal for your answer, – XS07 Jul 22 '11 at 23:26
  • Thanks for your answer, However, I tryed the command echo shell_exec('wkhtmltopdf --version -'); and it dose outputs the version info. but whene I run echo shell_exec('wkhtmltopdf www.google.com my.pdf'); It dose nothing, wkhtmltopdf is a package that take the url: www.google.com converted to pdf and save my.pdf to the same diractory. How can I handle a command line that result a pdf via php? – XS07 Jul 22 '11 at 23:34
2

To create a pdf from php(in linux) you must use a wrapper.

$cmd = '/usr/bin/xvfb-run --server-args="-screen 0, 1920x1080x24" /usr/bin/wkhtmltopdf http://google.com /tmp/google.pdf';

exec($cmd);