iTextSharp PdfPtable空白

时间:2014-11-05 16:03:08

标签: c# asp.net itextsharp

我整天都在绞尽脑汁。

这是代码:

    private void addFinalCheckdata()
    {
        PdfPTable table = new PdfPTable(10);
        float[] widths = new float[] { 60f, 60f, 60f, 60f, 60f, 60f, 60f, 60f, 260f, 60f };
        table.TotalWidth = 800f;
        table.SetWidths(widths);
        table.LockedWidth = true;
        table.HorizontalAlignment = 0;

        // Add Answers 
        //string value = _LGSRobj.finalCheck.SatisfactoryVisualInspection;
        PdfPCell cell = new PdfPCell(new Phrase("z", _fntNormal7));
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.EmergencyControl;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.EarthBondingSatisfactory;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.NumberofAppliancesTested;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.serviceTimerSet;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.StartPressure;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.FinishPressure;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.Pass;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.InstallationCaped;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        table.AddCell(cell);

        _document.Add(table);
    }

我已注释掉实际值并替换“z”以消除输入数据错误的可能性。 pdf上的每个其他表格都很好。只是这一个缺失。

我看不出代码有任何问题。也许这是iTextSharp或VS中的一个错误。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

当我复制/粘贴您的代码时,我在评论中添加了单元格编号,我得到了这个:

    private void addFinalCheckdata()
    {
        PdfPTable table = new PdfPTable(10);
        float[] widths = new float[] { 60f, 60f, 60f, 60f, 60f, 60f, 60f, 60f, 260f, 60f };
        table.TotalWidth = 800f;
        table.SetWidths(widths);
        table.LockedWidth = true;
        table.HorizontalAlignment = 0;

        // Add Answers 
        //string value = _LGSRobj.finalCheck.SatisfactoryVisualInspection;
        PdfPCell cell = new PdfPCell(new Phrase("z", _fntNormal7));
        // 1
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.EmergencyControl;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        // 2
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.EarthBondingSatisfactory;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        // 3
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.NumberofAppliancesTested;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        // 4
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.serviceTimerSet;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        // 5
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.StartPressure;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        // 6
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.FinishPressure;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        // 7
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.Pass;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        // 8
        table.AddCell(cell);

        //value = _LGSRobj.finalCheck.InstallationCaped;
        cell = new PdfPCell(new Phrase("z", _fntNormal7));
        // 9
        table.AddCell(cell);

        _document.Add(table);
    }

您正在创建一个包含10列的表:

PdfPTable table = new PdfPTable(10);

然而,你只增加了9个细胞。结果,该表不完整。如文档所示,永远不会显示不完整的行。

将表格更改为包含9列的表格,或者添加额外的单元格(如果您不想自己添加,可以自动执行此操作)。