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".
What is ITextSharp? iTextSharp is a free and open source assembly that helps to convert page output or HTML content in a PDF file. Now add that DLL in the application.
A Phrase is a series of Chunk s. A Phrase has a main Font , but some chunks within the phrase can have a Font that differs from the main Font . All the Chunk s in a Phrase have the same leading .
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();
}
Look at iText.pdf.PdfWriter. There are methods that take a stream.
Here's a sample for streaming in ASP.NET- link text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With