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:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...