Reputation: 10659
I need to attach a pdf I created in memory to an email. Attachments can take a stream. So I believe I need to convert a iTextSharp Document object to stream. How can I do that? I tried serializing the Document object to a stream but it is not "marked as serializable".
Upvotes: 8
Views: 31049
Reputation: 45947
Here is a approach, whith a new sample A4 document with "hello world" in it.
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
//creating a sample Document
iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 30f, 30f, 30f, 30f);
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, ms);
doc.Open();
doc.Add(new iTextSharp.text.Chunk("hello world"));
doc.Close();
byte[] result = ms.ToArray();
}
Upvotes: 24
Reputation: 29157
Look at iText.pdf.PdfWriter. There are methods that take a stream.
Here's a sample for streaming in ASP.NET- link text
Upvotes: 1