1

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);

.....

}
4

1 に答える 1

0

使用PdfPTable table = new PdfPTable(9);したのは、表の 9 列を意味します。「列」のようfloat[] widths = new float[] { 20f, 60f, 60f, 30f, 50f, 80f, 50f, 50f, 50f, 50f };に幅が設定されているので、変更してください。10そして使う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 };
于 2013-09-27T13:58:33.553 に答える