我想将 HTML 页面转换为 PDF 文档,但我的程序显示错误The number of columns in pdfptable constructor must be greater than zero
这是我的代码:
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=ulcact.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
tb1.RenderControl(hw);
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
StringReader sr = new StringReader(sw.ToString());
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
htmlparser.Parse(sr);//error should be gone
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
什么可能导致此错误,我该如何解决?