Tuesday, September 14, 2010

How to convert PDF document (custom object) to a byte array

string fileName = "application.pdf";
iTextSharp.text.Document doc = new iTextSharp.text.Document();
///
/// crate your pdf document
///
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream stream = new System.IO.MemoryStream();
binaryFormatter.Serialize(stream, doc);
byte[] bytes = stream.ToArray();
this.Response.Clear();
this.Response.AddHeader("content-disposition"string.Format("attachment;filename={0}"Path.GetFileName(fileName)));
this.Response.ContentType = "application/pdf";
this.Response.BinaryWrite(bytes);
this.Response.Flush();
this.Response.End();

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...