1

I need to export dx-data-grid(devExpress grid) to pdf document.There is a solution available to export data into excel, But how to export it to pdf?

Amit Chigadani
  • 28,482
  • 13
  • 80
  • 98
Bassem
  • 23
  • 2
  • 7
  • Please be clear what you want to achieve. – Amit Chigadani Aug 13 '17 at 16:01
  • need to click on button then all grid data export to PDF with same grid structure – Bassem Aug 13 '17 at 16:09
  • Support says: [At the moment, the PDF file format is not available for the grid widget. Only the Excel format is supported.](https://www.devexpress.com/Support/Center/Question/Details/T500288/how-to-export-dx-data-grid-to-pdf). – ventiseis Aug 13 '17 at 18:02

2 Answers2

1

At the moment this is not allowed on dxDataGrid, answer from DX support:

At the moment, dxDataGrid does not provide export to a PDF feature. We are aware of this limitation and this feature is in our TO-DO list. I can't, however, provide you with a precise date as to when it may be introduced. https://www.devexpress.com/Support/Center/Question/Details/T458071/dxdatagrid-is-it-possible-to-export-data-to-pdf

But you can generate your own pdf file in the server side of your app. using iTextSharp, this article shows how to do that 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();  
}  
}  

And then transfer it to your client How to download a file to client from server?

Victor Hugo Terceros
  • 2,969
  • 3
  • 18
  • 31
  • 1
    thanks you solution working, but i found solution without calling server again,Possible solution is to convert datasource of datagrid to html table. This example can be apply to datagrid too and used JS library to convert from HTML to PDF. this link help me to do that: https://www.devexpress.com/Support/Center/Question/Details/T113743/dxdatagrid-provide-the-capability-to-export-data – Bassem Aug 23 '17 at 08:31
  • Great to know you found an option, hopefully they will implement export to pdf in the next release – Victor Hugo Terceros Aug 23 '17 at 14:16
  • Sadly they will not implement it, they do not put it in root map for next releases – Bassem Aug 29 '17 at 09:50
1

devexpress makes it easy to export to pdf and other formats https://js.devexpress.com/Documentation/ApiReference/Common/Utils/pdfExporter/ (I have no affiliation with devexpress)

starball
  • 20,030
  • 7
  • 43
  • 238
Emma
  • 431
  • 6
  • 19
  • Thank Emma for your feedback. I discontinued using it a while ago, but it's great to hear that – Bassem Jun 29 '23 at 08:28