2010-03-24 916 views

回答

1

你能钻机像小高和文本=“---------”增加了新的段落

PdfPCell Cell = new PdfPCell(new Paragraph("------")); 
Cell.Height = 0.2f; 

您也可以自己使用PdfPCellEvent绘制边界。有不同的图层可以添加到。在此处查看API:http://api.itextpdf.com/com/itextpdf/text/pdf/PdfPCellEvent.html

+0

我想我们无法为电池组的高度? – 2010-03-24 11:58:00

1

如上所述,使用PdfPCellEvent。下面的代码应该可以帮你实现这个目标。 Cell event example.通过重写单元格事件,您基本上可以告诉iText您应该如何绘制单元格。无论何时将任何单元格添加到表格中,他们都将遵循您的规则。

class CustomCell implements PdfPCellEvent { 
public void cellLayout(PdfPCell cell, Rectangle rect, 
        PdfContentByte[] canvas) { 
        PdfContentByte cb = canvas[PdfPTable.LINECANVAS]; 
        cb.setLineDash(new float[] {3.0f, 3.0f}, 0);   
        cb.stroke(); 
      } 
} 

public class Main { 

     public static void main(String[] args) throws Exception { 
      Document document = new Document(); 
      PdfWriter.getInstance(document, new FileOutputStream("output.pdf")); 
      document.open(); 
      CustomCell border = new CustomCell(); 

      PdfPTable table = new PdfPTable(6); 
      PdfPCell cell; 

      for (int i = 1; i <= 6; i++) { 
       cell = new PdfPCell(new Phrase("test"));    
       cell.setCellEvent(border); 
       table.addCell(cell); 
      } 

      document.add(table); 
      document.close(); 
    } 
} 
+0

当我尝试你的代码时,E-Clipse发现了错误信息......“没有可用的pdf型封闭实例.....”任何想法发生了什么? – 2010-03-24 15:49:02

0
PdfPCell Border1 = new PdfPCell(new Paragraph("-----------------------------------------------------------------------------------------------------------------------")); 
      Border1.Border = 0; 
      Border1.VerticalAlignment = 3; 
      Border1.FixedHeight = 5F; 
      Border1.PaddingLeft = -5; 
      Border1.PaddingRight = -5; 
      Border1.PaddingBottom = -5; 
      Border1.PaddingTop = -5; 
1

细胞强调了与破折号:

public class UnderlinedCell implements PdfPCellEvent { 

    public void cellLayout(PdfPCell cell, Rectangle position, 
     PdfContentByte[] canvases) { 
     PdfContentByte canvas = canvases[PdfPTable.LINECANVAS]; 
     canvas.setLineWidth(0.5f); 
     canvas.setLineDash(3f, 3f); 
     canvas.moveTo(position.getLeft(), position.getBottom()); 
     canvas.lineTo(position.getRight(), position.getBottom()); 

     canvas.stroke(); 
    } 
}