【发布时间】:2013-09-27 13:53:16
【问题描述】:
我有一个代码可以使用带有表格的 iTextSharp 创建 PDF,但是当我将宽度设置为该表格时,它会抛出一个异常,指出该文档没有页面,为什么??
这是我的代码的一部分:
using (var document = new Document(PageSize.A4))
{
PdfWriter.GetInstance(document, new FileStream(string.Format("{0}{1}_test.pdf", outputPath, id), FileMode.Create));
document.Open();
//If add this line the exception is the same
//document.NewPage();
PdfPTable table = new PdfPTable(9);
table.TotalWidth = 500f;
float[] widths = new float[] { 20f, 60f, 60f, 30f, 50f, 80f, 50f, 50f, 50f, 50f };
//if this line is commented (table.SetWidths), the PDF works fine.
table.SetWidths(widths);
.....
}
【问题讨论】:
-
你能提供更多代码这么容易理解吗?
-
我不知道“更多代码”是什么意思...这是所有代码,table.SetWidths 之后的其余代码未达到,它只是 table.AddCell 代码...
-
我已经发布答案检查它。
标签: itextsharp