本文介绍了PdfPTable构造函数中的列数必须大于零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 ItextSharp 将html保存为PDF。我收到此错误: PdfPTable构造函数中的列数必须大于零。
我的代码片段:
I want to save a html as PDF using ItextSharp. I am getting this error:The number of columns in PdfPTable constructor must be greater than zero.
My Code Snippet:
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);
frmPrintHtml.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);//error occrs in this line
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
推荐答案
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);
frmPrintHtml.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();
这篇关于PdfPTable构造函数中的列数必须大于零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!