2014-11-26 4 views
0

하나의 상위 테이블 인 table_body를 사용했습니다. sub_table 하나의 자식 테이블 (나는이 sub_table 부모 테이블에있는 PdfPCell 안에 넣고 싶습니다.). 내 요구 사항에 따라 행이 부모 테이블에 대해 완료되면 선을 그립니다. 그러나이 문제는 서브 테이블과 보편적 인 pdfPcell의 bottomborder입니다. 'body_cell_bottomBorder'가 한 직선으로 정렬되지 않습니다.하위 테이블 셀과 부모 테이블의 일반 pdfPcell에 대한 Bottomborder가 iTextPDF에서 하나의 직선을 이루지 않습니다

PdfPTable table_body = new PdfPTable(2); // main table 
table_body.getDefaultCell().setBorder(Rectangle.NO_BORDER); // set border to none 
table_body.setWidthPercentage(100.0f); 
table_body.setWidths(new float[] {3.0f,1.0f,}); 
table_body.setSpacingBefore(6); 

PdfPTable sub_table = new PdfPTable(1); // sub table 
sub_table.getDefaultCell().setBorder(Rectangle.NO_BORDER); // set border to none 
body_cell_bottomBorder.setPhrase(new Phrase("Example",font_body)); // this cell has the bottom border only 
Image image = Image.getInstance(BarCode.createBarcode("example")); 
body_cell = new PdfPCell(image, true); // this cell has no border at all 
body_cell.setBorder(Rectangle.NO_BORDER); 
sub_table.addCell(body_cell); // added one row in the sub table 
sub_table.addCell(body_cell_bottomBorder); // added second row in the sub table and also want a bottom border 
table_body.addCell(sub_table); // added subtable into the parent table pdfpcell 

body_cell_bottomBorder.setPhrase(new Phrase(RPL,font_body)); // now adding second column value in parent table pdfPcell and want a bottom border only 
table_body.addCell(body_cell_bottomBorder); // added to the parent table 

문제는 부모 테이블의 두 셀이 내가 원하는 하나의 완전한 직선을 만들지 못한다는 것입니다. enter image description here

답변

0

한 가지 방법 : 추가 된 '아이'각 PdfPCellPdfPTable에서

  • 는 명시 적으로 Rectangle.NO_BORDER을 설정합니다.
  • '아동용'테이블을 완료하면 PdfPCell을 입력하고 테두리를 설정 한 다음 '부모'PdfPTable에 추가하십시오. C#에서

예,이 질문에 itextsharp 승/태그 때문에 :

string text = "0000"; 
int topBottomBorder = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER;  
using (Document document = new Document()) { 
    PdfWriter writer = PdfWriter.GetInstance(document, STREAM); 
    document.Open(); 
    PdfPTable parentTable = new PdfPTable(2); 
    PdfPCell cell = new PdfPCell() { 
    Phrase = new Phrase(text), Border = topBottomBorder 
    }; 
    parentTable.AddCell(cell); 

// in 'child' PdfPTable *ALL* PdfPCells set *WITH NO* border 
    PdfPTable childTable = new PdfPTable(1); 
    childTable.AddCell(new PdfPCell 
    (
     (new BarcodeQRCode(text, 1, 1, null)).GetImage() 
    ) 
    { Border = Rectangle.NO_BORDER, PaddingTop = 1 } 
); 
    childTable.AddCell(new PdfPCell() { // row 2 
    Border = Rectangle.NO_BORDER, Phrase = new Phrase(text) 
    }); 

// 1. wrap childTable in PdfPCell and set top & bottom borders 
    PdfPCell childTableCell = new PdfPCell(childTable) { 
    Border = topBottomBorder 
    }; 
// 2. add to main PdfPTable   
    parentTable.AddCell(childTableCell); 
    document.Add(parentTable); 
} 

결과 : Result:

+0

고마워요. 그게 내 문제를 해결해 줬어. 고마워요 :) – Ani