itext pdf和com.lowagie.text.table

itext pdf和com.lowagie.text.table,itext,Itext,如何避免iText中两个表之间的空格或间隙 使用com.lowagie.text.table类 Table table; com.lowagie.text.Cell cell; table = new Table(2); table.setPadding(2); table.setWidths(new int[] {100}); table.setWidth(100); cell = new com.lowagie.text.Cell(ne

如何避免iText中两个表之间的空格或间隙 使用com.lowagie.text.table类

    Table table;
    com.lowagie.text.Cell cell;
    table = new Table(2);
    table.setPadding(2);
    table.setWidths(new int[] {100});
    table.setWidth(100);
    cell = new com.lowagie.text.Cell(new Phrase(
            "sample text1", FontFactory
                    .getFont(FontFactory.HELVETICA, commonfontsize)));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setBorder(0);
    table.addCell(cell);
    document.add(table);
    table = new Table(2);
    table.setPadding(2);
    table.setWidths(new int[] {50,50});
    table.setWidth(100);
    cell = new com.lowagie.text.Cell(new Phrase(
            "sample text1", FontFactory
                    .getFont(FontFactory.HELVETICA, commonfontsize)));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setBorder(0);
    table.addCell(cell);
    cell = new com.lowagie.text.Cell(new Phrase(
            "sample text2", FontFactory
                    .getFont(FontFactory.HELVETICA, 10)));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    table.addCell(cell);
    document.add(table);

如何删除第一个表和第二个表之间的空间

这应该在PdfTable表前后留出空格


Table类在很多年前就被放弃了。您正在使用的iText版本也是如此。我建议您开始使用PdfPTable,而不是真正必须使用的表格!而且您升级到的iText版本在包名中没有提到我的名字。我是你在代码中引用的Lowagie!您好,谢谢您的回复,我需要避免两个表之间的默认间隙,这意味着表之间没有空间尝试此tb1.SetPackingBefore0f;其中tb1是不使用PdfPTable的第二个表对象,我使用的是com.lowagie.text.Table,它只有setspace方法。我在com.lowagie.text.Table中找不到任何方法,可以从上一个组件中删除空间。为什么不切换到我使用pdfwriter和rtfwriter进行相同的代码,具体取决于用户选择,但如果我使用itextpdf,我认为代码也应该更改
table.setSpacingBefore();      

table.setSpacingAfter();