How to increase the table height from the code behind file in ASP.Net while using StringWriter?
I am generating one PDF from the Code Behind File using StringWriter and HtmlTextWriter. The Coding is given below:
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView gv = new GridView();
gv.BorderStyle = BorderStyle.None;
gv.DataSource = dt2;
gv.DataBind();
gv.RenderControl(hw);
string str = sw.ToString();
string str1 = "<table width='100%' border='1'><tr><td><img src='" + Server.MapPath("App_Themes/Ribo/ribologo.bmp") + "' alt='' width=75px height=75px /></td><td align='center' colspan='8' font size='3'><h2><b>MATERIAL RECEIPT CUM INSPECTION REPORT(MRIR)</b></h2</td></tr>";
str1 += "<tr><td font size='3'>MRIR NO</td><td font size='3'>Date</td><td align='center' font size='3'>JOB DESCRIPTION</td><td font size='3'>SUPPLIER NAME</td><td font size='3'>DC NO</td><td font size='3'>DATE</td><td font size='3'>LWB NO/DATE</td><td font size='3'>INVOICE NO</td><td font size='3'>DATE</td></tr>";
str1 += "<tr><td font size='3'>" + txtMRVNumber.Text + "</td><td font size='3'></td><td font size='3'></td><td font size='3'>" + TDSSVendor.Text + "</td><td font size='3'>" + txtDCNumber.Text + "</td><td font size='3'></td><td font size='3'>" + txtLWBNo.Text + "</td><td font size='3'>" + txtInvoiceNo.Text + "</td><td font size='3'></td></tr>";
str1 += "<tr><td rowspan='2' font size='3'>DESCRIPTION</td><td font size='3' colspan='2' align='center'>SIZE(mm)</td><td colspan='6'></td></tr>";
str1 += "<tr><td font size='3' colspan='2'>" + sw + "</td><td colspan='6'></td></tr></table>";
if (str.StartsWith("<div>"))
{
str = str1;
}
System.IO.StringReader sr = new System.IO.StringReader(str);
iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A3.Rotate(), 40f, 10f, 40f, 2f);
iTextSharp.text.html.simpleparser.HTMLWorker htmlparser = new iTextSh开发者_运维知识库arp.text.html.simpleparser.HTMLWorker(pdfDoc);
iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
Here, I generated my desired PDF. But the table is displaying at the top of the PDF. So I want to display at the centre of the PDF as well as I want to increase the height of the Table. How to do this?
I tried like the below:
string str1 = "<table **height='100%'** width='100%' border='1'><tr>.....
But it displays as the same. How to increase the height of the table? I need all your suggestions please.
That alone is not going to do it. You can wrap the generated .pdf in another table (1 row, 1 column), and place that table in the sole TD of the new table, then just vertical align (valign='middle') the enclosing TD.
This is the only way I know how to do what you are asking, although I do not know if it will work for you:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Page</title>
<!-- Put this on your presentation page -->
<style type="text/css">
html, body {
margin: 0;
padding: 0;
height: 100%;
border: none;
}
</style>
</head>
<body>
<table style="height: 100%" width="100%" align="center">
<tr>
<td valign="middle" align="center">
<table>
<tr>
<td valign="middle">
<!-- Embed your .pdf here -->
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
from the taking the height of the table u can set parameter of below Document class constructor.
Dim doc As Document = New Document(PageSize.A4, 1, 0, 0, 30)
Hope this will helps you...
精彩评论