locked
Create Pdf from silverlight datagrid RRS feed

  • Question

  • After lots of effort I tired and post this thread here. Actually I want to export filtered, sorted or reordered data of silverlight datagrid to pdf without using third party tool if possible.

    If not possible please tell me which tool or dll or component is best to export datagrid data to excel and in pdf.

    Thanks in advance.

    Thursday, December 5, 2013 2:04 PM

Answers

  • Hello,

    Base on my experience, there is no direct way to export Silverlight datagrid data to PDF,  but you can achieve it using ITextSharp, take a look at here.

    In addition, silverPDF is a Silverlight library that makes it easier for developers to create PDF files on the client side. it is based on two excellent open source projects: PdfSharp (http://www.pdfsharp.net) and iTextSharp(http://itextsharp.sourceforge.net), more details please refer: http://silverpdf.codeplex.com/

    Here I list some similar issues for your reference:

    http://social.msdn.microsoft.com/Forums/en-US/63b1f14e-7482-4361-b5b6-ea3e334fd176/export-datagrid-to-pdf?forum=silverlightstart

    http://social.msdn.microsoft.com/Forums/en-US/home?category=silverlight&sort=relevancedesc&brandIgnore=True&searchTerm=export+to+pdf

    Hope this helps, thanks.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Yanping Wang Friday, December 6, 2013 6:57 AM
    • Proposed as answer by George Birbilis Friday, December 6, 2013 8:58 AM
    • Marked as answer by Yanping Wang Thursday, December 12, 2013 10:57 AM
    Friday, December 6, 2013 6:56 AM
  • iTextSharp.dll is best to use below is the code,you make a asp.net page and convert its content to pdf
    protected void btnSave_Click(object sender, EventArgs e)
    {
    
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=print.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    pdfPannel.RenderControl(hw);
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();
    
    }
    
    <asp:Panel ID="pdfPannel" runat="server">
    
          Sample Text
    <img src="../Images/image1.png"/>
    
    
    </asp:Panel>
    
    <asp:Button ID="btnSave" runat="server" Text="Save As PDF" onclick="btnSave_Click" />

    • Marked as answer by Yanping Wang Thursday, December 12, 2013 10:57 AM
    Friday, December 6, 2013 2:01 PM

All replies

  • Hello,

    Base on my experience, there is no direct way to export Silverlight datagrid data to PDF,  but you can achieve it using ITextSharp, take a look at here.

    In addition, silverPDF is a Silverlight library that makes it easier for developers to create PDF files on the client side. it is based on two excellent open source projects: PdfSharp (http://www.pdfsharp.net) and iTextSharp(http://itextsharp.sourceforge.net), more details please refer: http://silverpdf.codeplex.com/

    Here I list some similar issues for your reference:

    http://social.msdn.microsoft.com/Forums/en-US/63b1f14e-7482-4361-b5b6-ea3e334fd176/export-datagrid-to-pdf?forum=silverlightstart

    http://social.msdn.microsoft.com/Forums/en-US/home?category=silverlight&sort=relevancedesc&brandIgnore=True&searchTerm=export+to+pdf

    Hope this helps, thanks.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Yanping Wang Friday, December 6, 2013 6:57 AM
    • Proposed as answer by George Birbilis Friday, December 6, 2013 8:58 AM
    • Marked as answer by Yanping Wang Thursday, December 12, 2013 10:57 AM
    Friday, December 6, 2013 6:56 AM
  • iTextSharp.dll is best to use below is the code,you make a asp.net page and convert its content to pdf
    protected void btnSave_Click(object sender, EventArgs e)
    {
    
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=print.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    pdfPannel.RenderControl(hw);
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();
    
    }
    
    <asp:Panel ID="pdfPannel" runat="server">
    
          Sample Text
    <img src="../Images/image1.png"/>
    
    
    </asp:Panel>
    
    <asp:Button ID="btnSave" runat="server" Text="Save As PDF" onclick="btnSave_Click" />

    • Marked as answer by Yanping Wang Thursday, December 12, 2013 10:57 AM
    Friday, December 6, 2013 2:01 PM