2012-04-19 4 views
6

iTextSharp에서 테이블 (PdfPTable) 내에 셀 간격을 둘 수 있습니까? 나는 그것이 가능한 곳 어디에서도 볼 수 없다. iTextSharp.text.Table 대신에 iTextSharp (5.2.1)를 사용할 수있는 것은 아닙니다.iTextSharp 표 셀 간격 가능?

답변

1

테이블 클래스는 iTx에서 5.x부터 PdfPTable을 사용하여 제거되었습니다.

spacing은 찾고자하는 것이 setPadding 메소드입니다. 당신이 찾고 있다면

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

(그것은 자바 버전,하지만 C#을 포트는 방법의 이름 유지)

+4

감사를 시도하지만 (세포 내) 세포 패딩을 추가 할 수 있습니다 :

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(); } } 

그것을 사용합니다. 내가 필요로하는 것은 세포 간격 (세포 사이)이다. –

13

을 :

자세한 내용은이 iText의 API에서보세요 HTML의 경우와 같은 실제 셀 간격의 경우, PdfPTable은 기본적으로이를 지원하지 않습니다. 그러나 PdfPCell은 셀 레이아웃이 발생할 때마다 호출되는 IPdfPCellEvent의 사용자 지정 구현을 사용하는 속성을 지원합니다. 다음은 간단한 구현입니다. 필요에 맞게 조정할 수 있습니다.

//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

가하기에

 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);