Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
hii all,

i am export a web page in pdf format.. my code is working properly .. but my problem is that i m creating a table with column width and height.. when i run this page then table is showed properly with assigned width and height..

when i print as pdf as button click .. the all cloumn width is not working properly.. all the columns has same width..

there is no error in my code.. problem in my table format after print as pdf

where is problem. i m not able to find out..

my some code is:
HTML
<table align="center" bgcolor="#669999" cellpadding="0"
cellspacing="0" style="border: thin solid #333300;
width: 900px; height: 174px; text-align: center;" border="2">
    <tr>
       <td class="style3">
        <strong style="font-size: small">SI.No</strong></td>
    <td class="style4">
        <strong style="font-size: small">HH No</strong></td>
     <td class="style4">
        <strong style="font-size: small">Name of Children</strong></td>
    <td class="style3">
        <strong style="font-size: small">Male(M)<br />/Female(F)</strong></td>
  <td class="style4">
        <strong style="font-size: small">Date of Birth</strong></td>
     <td class="style3">
        <strong style="font-size: small">Disability(if any)</strong></td>
      <td class="style4">
        <strong style="font-size: small">Name of Father</strong></td>
      <td class="style4">
        <strong style="font-size: small">Name of Mother</strong></td>
    <td class="style3">
        <strong style="font-size: small">Caste</strong></td>
</tr>
</table>

my button click code is for export in pdf is:
C#
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 5f, 5f, 0f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
Posted
Updated 18-May-14 21:57pm
v2
Comments
Prasad Khandekar 19-May-14 4:08am    
Hello,

Try specifying the widths on each column in %.

Regards,

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