// Saving Invoice at DataBase public void InvoiceSave() { MemoryStream rtfStream = new MemoryStream(); MemoryStream pdfStream = new MemoryStream(); ASPxRichEdit1.SaveCopy(rtfStream, DocumentFormat.Rtf); ASPxRichEdit1.ExportToPdf(pdfStream); RichEditDocumentServer docServer = new RichEditDocumentServer(); docServer.LoadDocument(rtfStream, DocumentFormat.Rtf); using (SqlConnection con = new SqlConnection(conStr)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.Text; cmd.Connection = con; cmd.CommandText = @"update Invoices set InvoiceRtf = @InvoiceRtf, InvoicePdf = @InvoicePdf where OrderID = @OrderID"; cmd.Parameters.AddWithValue("@OrderID", HiddenInvoiceId.Value); cmd.Parameters.AddWithValue("@InvoiceRtf", SqlDbType.VarBinary).Value = rtfStream.ToArray(); cmd.Parameters.AddWithValue("@InvoicePdf", SqlDbType.VarBinary).Value = pdfStream.ToArray(); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } }
// Download PDF protected void btnPdf_Click(object sender, EventArgs e) { using (MemoryStream pdfStream = new MemoryStream()) { ASPxRichEdit1.ExportToPdf(pdfStream); HttpUtils.WriteFileToResponse(Page, pdfStream, "Invoice-Number-" + HiddenInvoiceId.Value, true, "pdf"); } }