Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,i am exporting my table in pdf format but while downloading text only displaying.but i need the table format in my pdf also.

What I have tried:

Controller

public FileResult Export(string GridHtml)
     {
         using (MemoryStream stream = new System.IO.MemoryStream())
         {
             StringReader sr = new StringReader(GridHtml);
             Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
             PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
             pdfDoc.Open();
             XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
             pdfDoc.Close();
             return File(stream.ToArray(), "application/pdf", "Grid.pdf");
         }


view page(button)

@using (Html.BeginForm("Export", "Home", FormMethod.Post))
   {
       <input type="hidden" name="GridHtml" />
       <input type="submit" id="btnSubmit" value="Export" />
   }
   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
   <script type="text/javascript">
   $(function () {
       $("#btnSubmit").click(function () {
           $("input[name='GridHtml']").val($("#Grid").html());
       });
   });
   </script>

view page(table)
<div id="Grid">
            @foreach (var item in Model.empinfo)
            {
                <table class="table table-bordered table-condensed table-striped">
                    <tr>
                        <td>Employee Name :</td>

                        <td>@item.FirstName @item.LastName</td>

                    </tr>
                    <tr>
                        <td>Designation :</td>
                        <td>@item.Designation</td>
                    </tr>
                </table>
                <table class="table table-bordered table-condensed table-striped">
                    <tr>
                        <td>
                            <table class="table table-bordered table-condensed table-striped">
                                <tr>
                                    <td colspan="2">Personal Details</td>
                                </tr>
                                <tr>
                                    <td>Email</td>
                                    <td>@item.Email</td>
                                </tr>
                                <tr>
                                    <td>DOB</td>
                                    <td>@item.DateOfBirth</td>
                                </tr>
                                <tr>
                                    <td>Address</td>
                                    <td>@item.Address</td>
                                </tr>
                                <tr>
                                    <td>Mobile No</td>
                                    <td>@item.PhoneNumber</td>
                                </tr>
                                <tr>
                                    <td>ZIP Code</td>
                                    <td>@item.Postalcode</td>
                                </tr>
                            </table>
                        </td>
                        <td>
                            <table class="table table-bordered table-condensed table-striped">
                                <tr>
                                    <td colspan="2">
                                        Employee Info
                                    </td>
                                </tr>
                                <tr>
                                    <td>Employee Id</td>
                                    <td>@item.EmployeeId</td>
                                </tr>
                                <tr>
                                    <td>Experience</td>
                                    <td>@item.Experience Year(s)</td>
                                </tr>

                                <tr>
                                    <td>Solution</td>
                                    <td>
                                        @item.Solutions
                                    </td>
                                </tr>
                                <tr>
                                    <td>Designation</td>
                                    <td>
                                        @item.Designation
                                    </td>
                                </tr>
                                <tr>
                                    <td>DOJ</td>
                                    <td>
                                        @item.DateOfJoining
                                    </td>
                                </tr>
                                <tr>
                                    <td>Hike Amount</td>
                                    <td>
                                        @item.HikeAmount
                                    </td>
                                </tr>

                            </table>
                        </td>
                    </tr>
                </table>
            }
        </div>
Posted
Comments
Wessel Beulink 11-Oct-17 5:16am    
Debug and look @Model.empinfo. What does it say?
Saineshwar Bageri 12-Oct-17 8:32am    
Try to write inline css to table and export html to pdf.
GrpSMK 16-Oct-17 2:28am    
Thank you guys i got solution...!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900