2009-07-28 38 views
7

Tôi cần đính kèm bản pdf tôi đã tạo trong bộ nhớ vào email. Tệp đính kèm có thể có luồng. Vì vậy, tôi tin rằng tôi cần phải chuyển đổi một đối tượng tài liệu iTextSharp để dòng. Làm thế nào tôi có thể làm điều đó? Tôi đã thử tuần tự hóa đối tượng Tài liệu thành luồng nhưng không được đánh dấu là có thể tuần tự hóa được.iTextSharp - Cách chuyển đổi Tài liệu thành byte []

Trả lời

17

Dưới đây là một mẫu mã

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(); 
} 
Các vấn đề liên quan