Hi, in web application:
Code:
protected void Page_Load(object sender, EventArgs e)
{
// Send PDF to browser
MemoryStream stream = new MemoryStream();
MyPDF.Documents.CreateAndSave(stream, false);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", stream.Length.ToString());
Response.AppendHeader("content-disposition", "attachment; filename=\"MyPDF.pdf\"");
Response.BinaryWrite(stream.ToArray());
Response.Flush();
stream.Close();
Response.End();
}
and in you MyPDF.Documents class:
Code:
public static void CreateAndSave(Stream stream, bool closeStream)
{
Document document = Documents.CreateDocument();
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
renderer.Document = document;
renderer.RenderDocument();
renderer.PdfDocument.Save(stream, closeStream);
}