2014-06-23 1 views
-2
Document document = new Document(); 
PdfPTable table = new PdfPTable(8); 
PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1")); 
PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2")); 
PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3")); 
PdfPCell cell4 = new PdfPCell(new Paragraph("Cell 4")); 
PdfPCell cell5 = new PdfPCell(new Paragraph("Cell 5")); 
PdfPCell cell6 = new PdfPCell(new Paragraph("Cell 6")); 
PdfPCell cell7 = new PdfPCell(new Paragraph("Cell 7")); 
PdfPCell cell8 = new PdfPCell(new Paragraph("Cell 8")); 
document.add(table); 

이 코드는 8 개의 셀이있는 테이블을 추가합니다. 내가 필요한 것은 같은 테이블에있는 또 다른 행입니다. 나는 어떻게해야 ..?테이블에 여러 행을 만들고 itext를 사용하여 페이지 중간에 놓습니다.

+0

의 중복 가능성 http://stackoverflow.com/questions/4891578/a-new-row-in- pdfptable) –

답변

1
Document document = new Document(); 
PdfPTable table = new PdfPTable(8); <-- This is a constructor. Above 8 cells, would automatically move to a new row. 
PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1")); 
PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2")); 
PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3")); 
PdfPCell cell4 = new PdfPCell(new Paragraph("Cell 4")); 
PdfPCell cell5 = new PdfPCell(new Paragraph("Cell 5")); 
PdfPCell cell6 = new PdfPCell(new Paragraph("Cell 6")); 
PdfPCell cell7 = new PdfPCell(new Paragraph("Cell 7")); 
PdfPCell cell8 = new PdfPCell(new Paragraph("Cell 8")); 

cell1 = new PdfPCell(new Paragraph("Cell 1")); 
cell2 = new PdfPCell(new Paragraph("Cell 2")); 
cell3 = new PdfPCell(new Paragraph("Cell 3")); 
cell4 = new PdfPCell(new Paragraph("Cell 4")); 
cell5 = new PdfPCell(new Paragraph("Cell 5")); 
cell6 = new PdfPCell(new Paragraph("Cell 6")); 
cell7 = new PdfPCell(new Paragraph("Cell 7")); 
cell8 = new PdfPCell(new Paragraph("Cell 8")); 
document.add(table); 

// 샘플/예 :

// a table with three columns 
    PdfPTable table = new PdfPTable(3); 
    // the cell object 
    PdfPCell cell; 
    // we add a cell with colspan 3 
    cell = new PdfPCell(new Phrase("Cell with colspan 3")); 
    cell.setColspan(3); 
    table.addCell(cell); 
    // now we add a cell with rowspan 2 
    cell = new PdfPCell(new Phrase("Cell with rowspan 2")); 
    cell.setRowspan(2); 
    table.addCell(cell); 
    // we add the four remaining cells with addCell() 
    table.addCell("row 1; cell 1"); 
    table.addCell("row 1; cell 2"); 
    table.addCell("row 2; cell 1"); 
    table.addCell("row 2; cell 2"); 
[pdfptable에서 새로운 행 (
+0

2 행 8 열 간단한 테이블이 필요합니다. 당신이 보여준 것은 약간 복잡했습니다 .. – Srinivasan

+0

@Srinivasan : 첫 번째 부분은 매우 간단합니다. 더 간단 할 수 없다 !!! 두 번째 코드 세트는 PDF 기능에 대한 이해를 돕기위한 것입니다. –

+0

첫 번째 코드 세트는 테이블에 2 행을 추가합니다. 어떻게 설명 할 수 있니? bcoz는 작동하지 않았다 .. !! – Srinivasan

관련 문제