【问题标题】:Itext : Split row issueItext:拆分行问题
【发布时间】:2015-07-28 10:40:22
【问题描述】:

我遇到了 Itext 的问题,在两页之间剪切了一行。我的代码是这样工作的:

PdfPTable Master = new PdfPTable(1);
Master.setHeaderRows(1);

PdfPTable Header = new PdfPTable(1);//create header table
//fill header
PdfPCell HeaderCell = new PdfPCell();
HeaderCell.addElement(Header);
Master.addCell(HeaderCell);//add header in master

foreach result in query
{
    float[] colsWidth = { 4f, 9f, 5f, 8f };
    PdfPTable Content = new PdfPTable(colsWidth);//create content table
    //fill content
    content.keepRowsTogether(0);
    PdfPCell ContentCell = new PdfPCell();
    ContentCell.addElement(Content);
    Master.addCell(ContentCell);//add header in master
}
document.add(Master);

但在 PDF 文档中,一些内容表被分成两页(因此,一些主表行)。 我尝试添加:

Master.keepRowsTogether(0);
Master.setSplitLate(false);

没有效果。

我也试过了:

Master.setSplitRows(false);

但这会使剪切的行简单地消失。 有人知道如何在主表中禁用行拆分吗?

【问题讨论】:

    标签: java itext


    【解决方案1】:

    在要拆分的单元格中也启用换行

    ContentCell .setNoWrap(false);
    

    所以

    foreach result in query
    {
        float[] colsWidth = { 4f, 9f, 5f, 8f };
        PdfPTable Content = new PdfPTable(colsWidth);//create content table
        //fill content
        content.keepRowsTogether(0);
        PdfPCell ContentCell = new PdfPCell();
       ContentCell .setNoWrap(false);
        ContentCell.addElement(Content);
        Master.addCell(ContentCell);//add header in master
    }
    

    别忘了Master.setSplitLate(false);

    【讨论】:

    • 我试过了,但不幸的是这并没有像写的那样工作,所以我尝试了不同的方法,通过添加“Master.keepRowsTogether(0)”来工作,所以谢谢 FevPlr。
    【解决方案2】:

    这适用于 itextsharp 5

    TableName.SplitLate = False

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 2011-06-13
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多