2017-08-13 56 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