/
Default.aspx.cs
46 lines (43 loc) · 1.8 KB
/
Default.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using DevExpress.XtraPrinting;
using System.Net.Mime;
using DevExpress.XtraPrintingLinks;
namespace WebApplication1 {
public partial class _Default : System.Web.UI.Page {
protected void ASPxButton1_Click(object sender, EventArgs e) {
using(MemoryStream ms = new MemoryStream()){
PrintableComponentLinkBase pcl = new PrintableComponentLinkBase(new PrintingSystemBase());
pcl.Component = ASPxGridView1;
pcl.Margins.Left = pcl.Margins.Right = 50;
pcl.Landscape = true;
pcl.CreateDocument(false);
pcl.PrintingSystemBase.Document.AutoFitToPagesWidth = 1;
pcl.ExportToPdf(ms);
WriteResponse(this.Response, ms.ToArray(), System.Net.Mime.DispositionTypeNames.Inline.ToString());
}
}
public static void WriteResponse(HttpResponse response, byte[] filearray, string type) {
response.ClearContent();
response.Buffer = true;
response.Cache.SetCacheability(HttpCacheability.Private);
response.ContentType = "application/pdf";
ContentDisposition contentDisposition = new ContentDisposition();
contentDisposition.FileName = "test.pdf";
contentDisposition.DispositionType = type;
response.AddHeader("Content-Disposition", contentDisposition.ToString());
response.BinaryWrite(filearray);
HttpContext.Current.ApplicationInstance.CompleteRequest();
try {
response.End();
}
catch (System.Threading.ThreadAbortException) {
}
}
}
}