我正在使用以下代码使用 iTextSharp 库版本 5.4.2 生成 PDF 文档。
// Create a Document object
var document = new Document(PageSize.A4, 50, 50, 25, 25);
// Create a new PdfWriter object, specifying the output stream
var output = new MemoryStream();
var writer = PdfWriter.GetInstance(document, output);
// Open the Document for writing
document.Open();
//Gets System.Web.UI.WebControls.Table
//Returns HTML table with 4 coulms
var flowsheetTable = GetTable(report);
var stringWriter = new StringWriter();
using (var htmlWriter = new HtmlTextWriter(stringWriter))
{
flowsheetTable.RenderControl(htmlWriter);
}
List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader(stringWriter.ToString()), null);
for (int k = 0; k < htmlarraylist.Count; k++)
{
document.Add((IElement)htmlarraylist[k]);
}
document.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=Receipt-test.pdf");
Response.BinaryWrite(output.ToArray());
GetTable() 方法返回一个具有 4 列的 System.Web.UI.WebControls.Table。有没有办法固定表格中第一列的宽度。我希望第一列占总宽度的 40%。
谢谢