2014-07-11 58 views
0

如何避免在iText的 两个表之间的空间或间隙使用类com.lowagie.text.tableiText的PDF与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); 

如何去除第一之间的空间桌子和第二张桌子?

+0

的'Table'类已经废弃很多年前后应该给予空间。那么您使用的是iText的版本。我建议你开始使用'PdfPTable'而不是'Table'(一个真正的!),并且你升级到一个iText的版本,它没有在包名中提到我的名字。 (我是您在代码中提到的Lowagie!) –

回答

0

这之前和PdfTable table

table.setSpacingBefore();  

table.setSpacingAfter(); 
+0

嗨,感谢您的回复,我需要避免两个表之间的默认间隔,这意味着在表 –

+0

之间没有空格试试'tb1.setSpacingBefore(0f);'where tb1是第二个表对象 – SparkOn

+0

我没有使用PdfPTable,我使用com.lowagie.text.Table和它只有setSpacing()方法 –