首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将dx-数据-网格devexpress导出到pdf?

如何将dx-数据-网格devexpress导出到pdf?
EN

Stack Overflow用户
提问于 2017-08-13 15:51:05
回答 1查看 2.9K关注 0票数 1

我需要导出dx-data-grid(devExpress网格)到pdf document.There是一个可用于导出数据到excel的解决方案,但如何将其导出到pdf?

EN

回答 1

Stack Overflow用户

发布于 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/

代码语言:javascript
复制
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?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45662165

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档