我需要导出dx-data-grid(devExpress网格)到pdf document.There是一个可用于导出数据到excel的解决方案,但如何将其导出到pdf?
发布于 2017-08-15 15:33:03
目前这在dxDataGrid上是不允许的,请从DX支持处回答:
目前,dxDataGrid不提供导出到PDF功能。我们意识到这一限制,这一特性在我们的待办事项清单中.不过,我不能给你一个确切的日期,什么时候可以推出。https://www.devexpress.com/Support/Center/Question/Details/T458071/dxdatagrid-is-it-possible-to-export-data-to-pdf
但是您可以在应用程序的服务器端生成自己的pdf文件。使用iTextSharp,本文展示了如何实现http://www.c-sharpcorner.com/UploadFile/f4f047/generating-pdf-file-using-C-Sharp/
using iTextSharp.text;
using iTextSharp.text.pdf;
protected void GeneratePDF(object sender, System.EventArgs e)
{
using(System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
Document document = new Document(PageSize.A4, 10, 10, 10, 10);
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
document.Open();
Chunk chunk = new Chunk("This is from chunk. ");
document.Add(chunk);
Phrase phrase = new Phrase("This is from Phrase.");
document.Add(phrase);
Paragraph para = new Paragraph("This is from paragraph.");
document.Add(para);
string text = @ "you are successfully created PDF file.";
Paragraph paragraph = new Paragraph();
paragraph.SpacingBefore = 10;
paragraph.SpacingAfter = 10;
paragraph.Alignment = Element.ALIGN_LEFT;
paragraph.Font = FontFactory.GetFont(FontFactory.HELVETICA, 12f, BaseColor.GREEN);
paragraph.Add(text);
document.Add(paragraph);
document.Close();
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
Response.Clear();
Response.ContentType = "application/pdf";
string pdfName = "User";
Response.AddHeader("Content-Disposition", "attachment; filename=" + pdfName + ".pdf");
Response.ContentType = "application/pdf";
Response.Buffer = true;
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
Response.Close();
}
} https://stackoverflow.com/questions/45662165
复制相似问题