title: How to Convert HTML/CSS to PDF in PHP on Linux
body: <p>I have been trying to convert an html page to PDF with out any luck, I have tried to use wkhtmltopdf (http://code.google.com/p/wkhtmltopdf/) and the PHP class provided by the same developers (http://code.google.com/p/wkhtmltopdf/wiki/IntegrationWithPhp) although the following command executed correctly in terminal:</p>
  
  <pre><code>wkhtmltopdf http:/www.googl.com test.pdf
  </code></pre>
  
  <p>I was unable to execute the command in PHP because of the following error:
  cannot connect to X server.</p>
  
  <p>Can any one provide me with a step-by-step tutorial in order to be able to convert html/css to PDF file, whether using wkhtmltopdf or any other decent solution.</p>
  
  <p>Thanks in advance</p>
  
  <p>here is the class that i have used <a href="http://code.google.com/p/wkhtmltopdf/wiki/IntegrationWithPhp" rel="nofollow">http://code.google.com/p/wkhtmltopdf/wiki/IntegrationWithPhp</a></p>
  
  <p>and below is my code</p>
  
  <pre><code>$html = file_get_contents("test.html");
  
  $pdf = new WKPDF();
  
  $pdf-&gt;set_html($html);
  
  $pdf-&gt;render();
  
  $pdf-&gt;output(WKPDF::$PDF_EMBEDDED,'sample.pdf');
  </code></pre>
  
  <p>Below is the error:</p>
  
  <pre><code>Fatal error: Uncaught exception 'Exception' with message 'WKPDF didn't return any data.
  /usr/bin/wkhtmltopdf: /opt/lampp/lib/libxml2.so.2: no version information available
  (required by /usr/lib/libgstreamer-0.10.so.0) No protocol specified wkhtmltopdf: cannot
  connect to X server :0 &lt;/pre&gt;' in /var/www/c4/components/com_wkhtmltopdf
  /wkhtmltopdf.class.php:211 Stack trace: #0 /var/www/c4/components/com_wkhtmltopdf
  /wkhtmltopdf.php(68): WKPDF-&gt;render() #1 /var/www/c4/components/com_wkhtmltopdf
  /wkhtmltopdf.php(50): html2pdf() #2 /var/www/c4/index2.php(114): require_once('/var/ww...') 
  #3 {main} thrown in /var/www/c4/components/com_wkhtmltopdf/wkhtmltopdf.class.php on line 211
  </code></pre>