4

I am trying to generate a PDF from HTML using PHP. I am running Mac OS X as my development environment although I would like this code to run on a production linux server.

So far I have got:

$url = escapeshellarg("http://www.google.com/");
$output = shell_exec("/usr/local/Cellar/wkhtmltopdf/0.11.0_rc1/bin/wkhtmltopdf " . $url . " /tmp/tmp_pdf.pdf 2>&1");
echo "<pre>$output</pre>";

This code does generate the PDF in the /tmp/tmp_pdf.pdf. The problem is it never does

echo "<pre>$output</pre>";

The browser just hangs saying waiting for server....

Its almost as if the shell_exec command never finishes. I notice when I run wkhtmltopdf from terminal it doesnt exit back to the command line. I get:

Loading page (1/2)
Printing pages (2/2)                                               
Done 

Then it sits there also, similar to the php script. Any ideas?

tdh87
  • 585
  • 1
  • 4
  • 8
  • How do you know it is waiting for the server? – hakre Aug 04 '12 at 09:43
  • 1
    What version of wkhtmltopdf are you using? I just tested the wkhtmltopdf-0.9.9-OS-X.i368 static binary on OS X 10.7.4 and it returned to the command line immediately after outputting "Done". – rexmac Aug 04 '12 at 10:21
  • @rexmac Thanks very much. Turns out I had used homebrew to install wkhtmltopdf. Using the static binary has fixed my problem. – tdh87 Aug 04 '12 at 10:34

1 Answers1

0

The problem was with the version used as rexmac pointed out. Using the static binary for wkhtmltopdf fixed the issue for OP.

Community
  • 1
  • 1
Joel Peltonen
  • 13,025
  • 6
  • 64
  • 100