I am trying to convert webpage content into pdf using itextsharp
following is the code
- protected void btnExport_Click(object sender, EventArgs e)
- {
- StringReader sr = new StringReader(Request.Form[hfGridHtml.UniqueID]);
- Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
- PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
- pdfDoc.Open();
- XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
- pdfDoc.Close();
- Response.ContentType = "application/pdf";
- Response.AddHeader("content-disposition", "attachment;filename=HTML.pdf");
- Response.Cache.SetCacheability(HttpCacheability.NoCache);
- Response.Write(pdfDoc);
- Response.End();
- }
and below is my source code
- <div class="Container" >
- <div>
- <table style="width: 100%" >
- <tr>
- <td style="font-weight: bold;font-size: 12px" colspan="2">
- </td>
- </tr>
- <tr>
- <td colspan="2"></td>
- </tr>
- <tr >
- <td style="font-size: 9px;height: 50px;width:50%">
- </td>
- <td align="right" style="font-weight: bold;font-size: 10px" > <div> <span>CENTRAL KYC REGISTRY</span>
- <span></span></div></td>
- </tr>
- </table>
- <table style="width: 100%; border-collapse:collapse" cellpadding="4" border="1">
- <tr>
- <td colspan="3" style="height: 25px;font-weight: bold;font-size: 12px">
- <div >1. Personal Details </div>
- </td>
- </tr>
- <tr>
- <td colspan="2" style="font-size: 10px; height: 3%"><span style="font-weight:bold;font-size: 10px"> Name* </span>(Same as ID proof): <asp:Label ID="lbName" runat="server" Text=""></asp:Label></td>
- <td rowspan="4" >
- <img src="" height="100" alt="" width="100" id="imgs" runat="server" ></ img>
- </td>
- </tr>
- <tr>
- <td style="height: 3%;font-size: 10px" colspan="2" >
- <div><span style="font-weight:bold" > Maiden name </span>(If any)* : <asp:Label ID="lbMaidenName" runat="server" Text=""></asp:Label></div> </td>
- </tr>
- <tr>
- <td style="height: 3%;font-size: 10px" colspan="2"><div><span style="font-weight:bold"> Father's/Spouse Name* </span>: <asp:Label ID="lbFatherName" runat="server" Text=""></asp:Label></div></td>
- </tr>
- <tr>
- <td style="height: 3%;font-size: 10px" colspan="2"><div><span style="font-weight:bold"> Mother name*</span> : <asp:Label ID="lbMotherName" runat="server" Text=""></asp:Label></div></td>
- </tr>
- </table>
- </div>
- </div>
while exporting it gives me error like this
'Invalid nested tag td found, expected closing tag img' and 'br'
I tried <img src='...'></img>and <br/>
But it gives me same error while exporting,
help me to resolve this issue, Thank you