export html form to pdf
<p>I have created an html form with a number of fields and I want to export the page to pdf.
The html code is as follows:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;form name="htmlform" method="post" action="html_form_send.php"&gt;
&lt;table width="450px"&gt;
&lt;/tr&gt;
&lt;tr&gt;
 &lt;td valign="top"&gt;
  &lt;label for="first_name"&gt;First Name *&lt;/label&gt;
 &lt;/td&gt;
 &lt;td valign="top"&gt;
  &lt;input  type="text" name="first_name" maxlength="50" size="30"&gt;
 &lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
 &lt;td valign="top""&gt;
  &lt;label for="last_name"&gt;Last Name *&lt;/label&gt;
 &lt;/td&gt;
 &lt;td valign="top"&gt;
  &lt;input  type="text" name="last_name" maxlength="50" size="30"&gt;
 &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
 &lt;td valign="top"&gt;
  &lt;label for="email"&gt;Email Address *&lt;/label&gt;
 &lt;/td&gt;
 &lt;td valign="top"&gt;
  &lt;input  type="text" name="email" maxlength="80" size="30"&gt;
 &lt;/td&gt;

&lt;/tr&gt;
&lt;tr&gt;
 &lt;td valign="top"&gt;
  &lt;label for="telephone"&gt;Telephone Number&lt;/label&gt;
 &lt;/td&gt;
 &lt;td valign="top"&gt;
  &lt;input  type="text" name="telephone" maxlength="30" size="30"&gt;
 &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
 &lt;td valign="top"&gt;
  &lt;label for="comments"&gt;Comments *&lt;/label&gt;
 &lt;/td&gt;
 &lt;td valign="top"&gt;
  &lt;textarea  name="comments" maxlength="1000" cols="25" rows="6"&gt;&lt;/textarea&gt;
 &lt;/td&gt;

&lt;/tr&gt;
&lt;tr&gt;
 &lt;td colspan="2" style="text-align:center"&gt;
  &lt;input type="submit" value="Submit"&gt;  
 &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;form action="myphpfile.php" method="post"&gt;
  &lt;input type="submit" value="Download as pdf!"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I have got the php code to export the form to pdf from <a href="http://freehtmltopdf.com/" rel="nofollow">http://freehtmltopdf.com/</a> but whenever I click on the"Download as pdf" button it simply shows me the php code in the file. I have my webserver running on XAMP and the html file is in htdocs. I need further help in converting this html to pdf.</p>

<p>The php code I got from the site is:</p>

<pre><code>&lt;?php

    $url = 'http://freehtmltopdf.com';
    $data = array(  'convert' =&gt; '', 
            'html' =&gt; '&lt;html&gt;&lt;head&gt;&lt;title&gt;My Title&lt;/title&gt;&lt;link rel="stylesheet" type="text/css" href="relativepath.css"&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Web Page&lt;/h1&gt;&lt;p&gt;This is my content.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;',
            'baseurl' =&gt; 'http://www.myhost.com');

    // use key 'http' even if you send the request to https://...
    $options = array(
        'http' =&gt; array(
            'header'  =&gt; "Content-type: application/x-www-form-urlencoded\r\n",
            'method'  =&gt; 'POST',
            'content' =&gt; http_build_query($data),
        ),
    );
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);

    // set the pdf data as download content:
    header('Content-type: application/pdf');
    header('Content-Disposition: attachment; filename="webpage.pdf"');
    echo($result);

?&gt;
</code></pre>