Click here to Skip to main content
15,888,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am exporting Html tables via Itextsharp to PDF . It is working fine. There are 2 html tables and those are coming vertically. I need to have them aligned horizontally left and right.
Below is my core html code:
<div>
       <asp:Panel ID="pnltest"  runat="server" >
   <table border = "1" width = "100" style="float:left">
   <tr><td>Name</td><td>Age</td></tr>


   </table>
   <table border = "1" width = "100" style="float:left">
   <tr><td>Name</td><td>Age</td></tr>


   </table>
           </asp:Panel>
   </div>


What I have tried:

Exported html tables via itextsharp dll to PDF. But the table alignment on rendering is coming vertically instead of horizontally.
Posted
Updated 3-Jan-17 18:04pm

1 solution

Hi,

It's better to use code behind rather than HTML to show tables on PDF page. It provides flexibility to design your tables.

follow these code to solve your problem:

PdfPTable table = new PdfPTable(5); 
            // To show data in table.
            // "5" total number of columns.


            // Here I have set width of every columns.
            float[] widths = new float[] { 100f, 80f, 100f, 90f, 130f };
            table.SetWidths(widths);

            // Name of the header for each column.
            table.AddCell("Name");
            table.AddCell("Age");
            table.AddCell("Band");
            table.AddCell("Designation");
            table.AddCell("Current Project");

            // Adding value in the table.
            // If you are getting list values the use FOREACH loop to show all data in                                                     table  
            table.AddCell(emp.Name);
            table.AddCell(emp.Age.ToString());
            table.AddCell(emp.Band);
            table.AddCell(emp.Designation);
            table.AddCell(emp.Project);
            
            // Here I am adding table to the document.
            document.Add(table);


To get more information check this link:

How to download pdf in MVC[^]
 
Share this answer
 
v2

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