2012-04-19 76 views

Respuesta

1

La clase Table se ha eliminado de iText a partir de 5.x, a favor de PdfPTable.

En cuanto al espaciado, lo que está buscando son los métodos setPadding.

Tener un vistazo a la API de iText para más información:

http://api.itextpdf.com/itext/com/itextpdf/text/pdf/PdfPCell.html

(Es para la versión de Java, pero el puerto C# mantiene los nombres de los métodos)

+4

Gracias por eso, sino que es para agregar el relleno de celdas (dentro de la célula). Lo que necesito es espacio entre celdas (entre las celdas). –

13

Si está buscando para un verdadero espaciado de celdas como HTML, entonces no, el PdfPTable no es compatible de forma nativa. Sin embargo, el PdfPCell admite una propiedad que toma una implementación personalizada de IPdfPCellEvent que se llamará siempre que se produzca un diseño de celda. A continuación se muestra una implementación simple de uno, es probable que desee ajustarlo a sus necesidades.

public class CellSpacingEvent : IPdfPCellEvent { 
    private int cellSpacing; 
    public CellSpacingEvent(int cellSpacing) { 
     this.cellSpacing = cellSpacing; 
    } 
    void IPdfPCellEvent.CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { 
     //Grab the line canvas for drawing lines on 
     PdfContentByte cb = canvases[PdfPTable.LINECANVAS]; 
     //Create a new rectangle using our previously supplied spacing 
     cb.Rectangle(
      position.Left + this.cellSpacing, 
      position.Bottom + this.cellSpacing, 
      (position.Right - this.cellSpacing) - (position.Left + this.cellSpacing), 
      (position.Top - this.cellSpacing) - (position.Bottom + this.cellSpacing) 
      ); 
     //Set a color 
     cb.SetColorStroke(BaseColor.RED); 
     //Draw the rectangle 
     cb.Stroke(); 
    } 
} 

utilizarlo:

//Create a two column table 
PdfPTable table = new PdfPTable(2); 
//Don't let the system draw the border, we'll do that 
table.DefaultCell.Border = 0; 
//Bind our custom event to the default cell 
table.DefaultCell.CellEvent = new CellSpacingEvent(2); 
//We're not changing actual layout so we're going to cheat and padd the cells a little 
table.DefaultCell.Padding = 4; 
//Add some cells 
table.AddCell("Test"); 
table.AddCell("Test"); 
table.AddCell("Test"); 
table.AddCell("Test"); 

doc.Add(table); 
-4

probarlo

 PdfPTable table = new PdfPTable(2); 
     table.getDefaultCell().setBorder(0); 
     table.getDefaultCell().setPadding(8); 
     table.addCell("Employee ID"); 
     table.addCell(""); 
     table.addCell("Employee Name"); 
     table.addCell(""); 
     table.addCell("Department"); 
     table.addCell(""); 
     table.addCell("Place"); 
     table.addCell(""); 
     table.addCell("Contact Number"); 
     table.addCell(""); 
     document.add(table); 
Cuestiones relacionadas