2017-08-13 70 views
0

我需要将dx-data-grid(devExpress网格)导出为pdf文档。有一种可用于将数据导出到excel的解决方案,但是如何将其导出为pdf?如何将dx-data-grid devexpress导出为pdf?

+0

请清楚你想要达到的目标。 –

+0

需要点击按钮,然后所有网格数据导出为PDF格式相同的网格结构 – Bassem

+0

支持说:[此刻,PDF文件格式不可用于网格小部件。只支持Excel格式。](https://www.devexpress.com/Support/Center/Question/Details/T500288/how-to-export-dx-data-grid-to-pdf)。 – ventiseis

回答

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?

+0

谢谢你解决方案的工作,但我发现解决方案没有再次调用服务器,可能的解决方案是将数据网格的数据源转换为HTML表格。这个例子也可以应用于datagrid,并使用JS库从HTML转换为PDF。这个链接帮助我做到这一点:https://www.devexpress.com/Support/Center/Question/Details/T113743/dxdatagrid-provide-the-capability-to-export-data – Bassem

+0

很高兴知道您找到了一个选项,希望他们能够在下一个版本中实现导出为pdf的格式 –

+0

很遗憾,他们不会实现它,他们不会将其放入根地图中用于下一个版本 – Bassem