Tuesday, July 28, 2009

iTextSharp - Sending in-memory pdf in an email attachment

I was helping a client with the good old task of printing reports in a pdf format from an Asp.Net page, without having to use a commercial tool. I did a bit of research on iTextSharp and it appears to do everything I need. For instance, one of my goals was to be able to create a pdf file in memory and send it as an email attachment. Here's the code I used to do that:(In this example I use gmail as my smtp server, so it makes it easier for you to try it for yourself)