Snehal Pawar

Snehal Pawar

  • NA
  • 25
  • 20k

Page breaking in Itextsharp

Oct 31 2017 8:01 AM
I am trying to convert webpage into pdf using itextsharp,
 
Following is the c# code I am using  
 
protected void btnExport_Click(object sender, EventArgs e)
{
try
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.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, 10f, 10f, 5f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
StyleSheet ST = new StyleSheet();
FontFactory.Register("c:\\windows\\fonts\\Times.ttf");
ST.LoadTagStyle("body", "face", "Times New Roman");
ST.LoadTagStyle("body", "size", "15px");
htmlparser.SetStyleSheet(ST);
//XMLWorkerHelper worker = XMLWorkerHelper.GetInstance();
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
catch (Exception EX)
{ }
}
 
 
 
below is a source code:
 
 
<div id="pdf" class="Container" runat="server">
<div >
<div>
<table style="width: 100%" >
<tr>
<td style="font-weight: bold;font-size: 14px" colspan="2"><div>
<span ></span></div></td>
</tr>
<tr>
<td colspan="2"><div><span ></span></div></td>
</tr>
<tr >
<td style="font-size: 10px;height: 50px;width:50%">
<div>
<span></span>
<span></span>
</div>
</td>
<td align="right" style="font-weight: bold;font-size: 10px" > <div> <span></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 style="height: 60%" colspan="2"><span style="font-weight:bold"> Name* </span>(Same as ID proof): <asp:Label ID="lbName" runat="server" Text=""></asp:Label></td>
<td rowspan="4" >
<img height="100" alt="" width="100" id="imgs" runat="server" />
</td>
</tr>
<tr>
<td style="height: 20px;" 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: 20px" 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: 20px" colspan="2"><div><span style="font-weight:bold"> Mother name*</span> : <asp:Label ID="lbMotherName" runat="server" Text=""></asp:Label></div></td>
</tr>
</table>
<table style="width: 100%;border-collapse:collapse" cellpadding="4" border="1">
<tr>
<td ><div><span style="font-weight:bold">Date of birth*</span> : <asp:Label ID="lbDOB" runat="server" Text=""></asp:Label> </div></td>
<td><div><span style="font-weight:bold"> Gender*</span> : <asp:Label ID="lbGender" runat="server" Text=""></asp:Label> </div> </td>
</tr>
<tr>
<td ><div><span style="font-weight:bold"> Marital status*</span> : <asp:Label ID="lbMarital" runat="server" Text=""></asp:Label></div></td>
<td><div><span style="font-weight:bold"> Citizenship*</span> : <asp:Label ID="lbcitizen" runat="server" Text="Indian"></asp:Label></div> </td>
</tr>
<tr>
<td ><div><span style="font-weight:bold">Residential status* </span>: <asp:Label ID="lbResiden" runat="server" Text="Resident individual"></asp:Label> </div></td>
<td><div><span style="font-weight:bold"> Occupation Type*</span> : <asp:Label ID="lboccup" runat="server" Text=""></asp:Label> </div> </td>
</tr>
<tr>
<td><span style="font-weight:bold">Pan card*</span> :<asp:Label ID="lbpan" runat="server" Text=""></asp:Label></td>
<td><div><span style="font-weight:bold"> Adhar Card*</span> :<asp:Label ID="lbaadhar" runat="server" Text=""></asp:Label> </div> </td>
</tr>
</table>
<table cellpadding="4" style="width: 100%; border-collapse:collapse" border="1">
<tr>
<td colspan="2" style="height: 25px;font-weight: bold;font-size: 12px">
<div ><span style="font-weight:bold">2. Residence for tax purposes in jurisdiction(s) outside India</span> </div>
</td>
</tr>
<tr>
<td> <asp:Label ID="taxno" runat="server" Text="NO" Visible ="false"></asp:Label> </td>
</tr>
</table>
<table cellpadding="4" id="tax" runat="server" style="width: 100%; border-collapse:collapse" border="1">
<tr>
<td colspan="2"><span style="font-weight:bold">ISO 3166 Country Code of Jurisdiction of Residence*</span> : <asp:Label ID="lbtaxCC" runat="server" Text=""></asp:Label> </td>
</tr>
<tr>
<td colspan="2"><span style="font-weight:bold">Tax Identification Number*</span> : <asp:Label ID="lbtid" runat="server" Text=""></asp:Label> </td>
</tr>
<tr>
<td ><span style="font-weight:bold">Place/City of Birth*:</span> <asp:Label ID="lbtaxPOB" runat="server" Text=""></asp:Label></td>
<td><span style="font-weight:bold">ISO 3166 Country Code*:</span> <asp:Label ID="lbCC" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td colspan="2">ADDRESS IN THE JURISDICTION DETAILS WHERE APPLICANT IS RESIDENT OUTSIDE INDIA FOR TAX PURPOSE*</td>
</tr>
<tr>
<td style="font-weight:bold" colspan="2"><span style="font-weight:bold">Address:</span> <asp:Label ID="taxadd" runat="server" Text=""></asp:Label> </td>
</tr>
<tr>
<td runat="server" id="taxcity" ><span style="font-weight:bold">City/Town/Village:</span> <asp:Label ID="Label29" runat="server" Text=""></asp:Label> </td>
<td runat="server" id="taxpin" ><span style="font-weight:bold">Pincode:</span> <asp:Label ID="Label30" runat="server" Text=""></asp:Label> </td>
</tr>
<tr>
<td runat="server" id="taxcc" ><span style="font-weight:bold">ISO 3166 Country code:</span> <asp:Label ID="Label32" runat="server" Text=""></asp:Label> </td>
<td runat="server" id="taxsc" ><span style="font-weight:bold">State code: </span> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </td>
</tr>
</table>
<table cellpadding="4" style="width: 100%; border-collapse:collapse" border="1">
<tr>
<td colspan="2" style="height: 25px;font-weight: bold;font-size: 12px">
<div >3. Address </div>
</td>
</tr>
<tr>
<td ><span style="font-weight:bold">Address :</span> <asp:Label ID="lbaddtype" runat="server" Text=""></asp:Label> </td>
</tr>
<tr>
<td ><span style="font-weight:bold">City/Town/Village:</span> <asp:Label ID="lbcity" runat="server" Text=""></asp:Label> </td>
<td ><span style="font-weight:bold">Pincode:</span> <asp:Label ID="lbpincode" runat="server" Text=""></asp:Label> </td>
</tr>
<tr>
<td ><span style="font-weight:bold">District:</span> <asp:Label ID="lbdist" runat="server" Text=""></asp:Label> </td>
<td ><span style="font-weight:bold">ISO 3166 Country code:</span> <asp:Label ID="Label19" runat="server" Text=""></asp:Label> </td>
</tr>
<tr>
<td colspan="2" ><span style="font-weight:bold">State code:</span> <asp:Label ID="Label2" runat="server" Text=""></asp:Label> </td>
</tr>
<tr>
<td colspan="2">CORRESPONDENCE/LOCAL ADDRESS DETAILS*: <asp:Label ID="Label33" runat="server" Text=""></asp:Label> </td>
</tr>
<tr>
<td> <asp:Label ID="lbsameasperm" runat="server" Text="Same AS PERMANENT" Visible ="false"></asp:Label> </td>
</tr>
</table>
<table cellpadding="4" id ="sameascorr" runat="server" style="width: 100%; border-collapse:collapse" border="1">
<tr>
<td colspan="2"><span style="font-weight:bold">Address:</span> <asp:Label ID="Label38" runat="server" Text=""></asp:Label> </td>
</tr>
<tr>
<td style=" width:20%"><span style="font-weight:bold">City/Town/Village:</span> <asp:Label ID="Label34" runat="server" Text=""></asp:Label> </td>
<td style=" width:20%"><span style="font-weight:bold">Pincode:</span> <asp:Label ID="Label35" runat="server" Text=""></asp:Label> </td>
</tr>
<tr>
<td style=" width:20%"><span style="font-weight:bold">District:</span> <asp:Label ID="Label36" runat="server" Text=""></asp:Label> </td>
<td style=" width:20%"><span style="font-weight:bold">ISO 3166 Country code:</span> <asp:Label ID="Label37" runat="server" Text=""></asp:Label> </td>
</tr>
<tr>
<td style=" width:20%" colspan="2"><span style="font-weight:bold">State code:</span> <asp:Label ID="Label3" runat="server" Text=""></asp:Label> </td>
</tr>
</table>
<table cellpadding="4" style="width: 100%; border-collapse:collapse" border="1">
<tr>
<td colspan="2" style=" font-weight: bold;font-size: 12px">
<div >4. Contact Details </div>
</td>
</tr>
<tr>
<td style="height: 20px"><span style="font-weight:bold">Mobile:</span> <asp:Label ID="lbmobile" runat="server" Text=""></asp:Label> </td>
<td style="height: 20px"><span style="font-weight:bold">Email Id:</span> <asp:Label ID="lbemail" runat="server" Text=""></asp:Label> </td>
</tr>
</table>
<table cellpadding="4" style="width: 100%; border-collapse:collapse" border="1">
<tr>
<td colspan="2" style=" font-weight: bold;font-size: 12px">
<div >5. Applicant Decalartion </div>
</td>
</tr>
<tr>
<td style="height:20px;width: 60%"><span style="font-weight:bold">I here by declare that the details furnished above are true and correct to the best of my knowledge and belief and I undertake to inform you of any changes therein. immediately. In case any of the above information is found to be false or untrue or misleading or misrepresenting. I am aware that I may be held liable for it </span> </td>
<td rowspan="3" bgcolor="#dbdbdb"> </td>
</tr>
<tr>
<td style="height:20px"> </td>
</tr>
<tr>
<td style="height:20px"> </td>
</tr>
<tr>
<td><span style="font-weight:bold"> DATE :</span> <asp:Label ID="lbdate" runat="server" Text=""></asp:Label> </td>
<td><span style="font-weight:bold"> Place :</span> <asp:Label ID="Label25" runat="server" Text=""></asp:Label> </td>
</tr>
</table>
</div>
<div style="page-break-after : always">
<table cellpadding="4" style="width: 100%;page-break-after : always">
<tr><td colspan="2" style="border-bottom:1px solid"></td></tr>
<tr>
<td style="font-weight: bold;font-size: 14px" colspan="2"><div>
<span ></span></div></td>
</tr>
<tr>
<td colspan="2"><div><span ></span></div></td>
</tr>
<tr >
<td style="font-size: 10px;height: 50px;width:50%">
<div>
<span> </span>
<span></span>
</div>
</td>
<td align="right" style="font-weight: bold;font-size: 10px" > <div> <span></span>
<span></span></div></td>
</tr>
</table>
<table cellpadding="4" style="width: 100%; border-collapse:collapse" border="1" >
<tr>
<td colspan="3" align="center" style=" font-size: 12px">
<div >Annexture- 3 </div>
</td>
</tr>
<tr>
<td align="center" colspan="4" style=" font-weight: bold;font-size: 12px">
<div >TRADING AND DEMAT ACCOUNT RELATED DETAILS </div>
</td>
</tr>
<tr>
<td colspan="4" style="height: 20px">A. NAME OF THE APPLICANT </td>
</tr>
<tr>
<td style="height: 20px; width:25% "><span style="font-weight:bold">Trading Account Holder Name:</span><asp:Label ID="tdacc" runat="server" Text=""></asp:Label> </td>
<td style="height: 20px; width:25% " ><span style="font-weight:bold">DP Holder Name:</span></td>
</tr>
</table>
</div>
</div>
</div>
 
 
 

Answers (1)