我需要将我在内存中创建的pdf附加到电子邮件中。附件可以采取流程。所以我认为我需要将iTextSharp Document对象转换为流。我怎样才能做到这一点? 我尝试将Document对象序列化为流,但它没有“标记为可序列化”。
答案 0 :(得分:19)
这是一个代码示例
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();
}
答案 1 :(得分:1)
看看iText.pdf.PdfWriter。有一些方法需要流。
以下是ASP.NET中的流式传输示例 - link text