我需要将dx-data-grid
(devExpress网格)导出到pdf文档。有一个解决方案可用于将数据导出到excel,但是如何将其导出为pdf?
答案 0 :(得分:1)
目前dxDataGrid上不允许这样做,请回答DX支持:
目前,dxDataGrid不提供导出到PDF功能。我们知道这个限制,这个功能在我们的TO-DO列表中。但是,我无法为您提供何时可以引入的确切日期。 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();
}
}
然后将其转移到您的客户端 How to download a file to client from server?