1. First you need to download an itextsharp. dll http://somewebguy.wordpress.com/2009/05/08/itextsharp-simplify-your-html-to-pdf-creation/
2. Find an htmltow.builder. CS file in the URL and introduce it to your project.
3. Create a pdfresult class
Public class pdfresult: actionresult
{
Public override void executeresult (controllercontext context)
{
Htmltow.builder builder = new htmltow.builder (pagesize. letter );
Htmlpdfpage page1 = builder. addpage ();
Page1.appendhtml ("Page1.appendhtml ("<p> Andrew Cycler <br> ");
Page1.appendhtml ("4254 some street <br> ");
Page1.appendhtml ("Los Angeles, CA </P> ");
Page1.appendhtml ("<Table> <tr> <TD> <B> product </B> </TD> <B> price </B> </TD> </tr> ");
Page1.appendhtml ("<tr> <TD> ASP. net mvc cookbook </TD> <TD> $40.00 </TD> </tr> </table> ");
Byte [] buffer = new byte [4096];
Byte [] file = builder. renderpdf ();
Httpresponsebase response = context. httpcontext. response;
Response. contenttype = "application/pdf ";
Memorystream multicast stream = new memorystream (File );
While (true)
{
Int READ = mongostream. Read (buffer, 0, buffer. Length );
If (read = 0)
Break;
Response. outputstream. Write (buffer, 0, read );
}
Response. End ();
}
}
4. Implement an action (getpdf) in homecontroller)
Public pdfresult getpdf ()
{
Return new pdfresult ();
}
5. In the index view, add a connection-oriented getpdf
Click <% = html. actionlink ("here", "getpdf", "home") %> to get your order in pdf format!
OK. Make sure you are happy.