【问题标题】:iTextSharp The document has no pages. when SetWidths on table?iTextSharp 文档没有页面。什么时候在桌子上设置宽度?
【发布时间】: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


【解决方案1】:

您使用了PdfPTable table = new PdfPTable(9); 表示9 列表格。 你被设置了宽度 像float[] widths = new float[] { 20f, 60f, 60f, 30f, 50f, 80f, 50f, 50f, 50f, 50f }; for 10 'columns' 所以请更改它。 并使用float[] widths = new float[] { 20f, 60f, 60f, 30f, 50f, 80f, 50f, 50f, 50f};

然后它的工作。

使用这个,

PdfPTable table = new PdfPTable(10);
table.TotalWidth = 500f;
float[] widths = new float[] { 20f, 60f, 60f, 30f, 50f, 80f, 50f, 50f, 50f, 50f };

【讨论】:

  • 天啊!!!!该死!抱歉这个问题,这就是问题所在!但是......来吧 iTextSharp.. 错误可能更具体 LOL。
  • 上次使用的document.Add(table);document.Close();
猜你喜欢
  • 1970-01-01
  • 2012-04-03
  • 2013-10-17
  • 1970-01-01
  • 2014-07-27
  • 2012-08-22
  • 2014-07-18
  • 1970-01-01
  • 2015-03-18
相关资源
最近更新 更多