单击按钮时,我需要阅读 HTML 文件并将其转换为 PDF。PDF 生成没有任何问题。但是当转换为 PDF 时,表格中的列宽是均匀分布的。但我需要表格的第一列占表格总大小的 70% (540)
我怎样才能做到这一点?
模板.html:
<table runat="server" id="header" border="3" width="540">
<tr>
<td style="width:70%; text-align: center; font-weight: bold;">
<strong>Test Specification </strong>
</td>
<td style="width:10%; text-align: center; font-weight: bold;">
<strong>GST </strong>
</td>
<td style="width:10%; text-align: center; font-weight: bold;">
<strong>Service </strong>
</td>
<td style="width:10%; text-align: center; font-weight: bold;">
<strong>Amount </strong>
</td>
</tr>
</table>
按钮单击以将 HTML 转换为 PDF:
protected void Button1_Click(object sender, EventArgs e)
{
String htmlText = System.IO.File.ReadAllText(Request.PhysicalApplicationPath + "\\Template.htm");
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + DateTime.Now.ToString("ddMMyyyy") + "_" + DateTime.Now.ToString("HHmmss tt") + ".pdf", FileMode.Create));
document.Open();
iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
hw.Parse(new StringReader(HTML));
document.Close();
StringBuilder sb = new StringBuilder();
sb.Append(HTML);
}