iText를 사용하여 테이블이있는 pdf 또는 rtf 파일을 생성하는 프로그램을 작성 중입니다. 더 구체적인 RtfTable 또는 pdfTable보다는 iText 클래스 테이블과 셀을 사용하여 어느 파일이든 끝에 생성 될 수 있도록했습니다. 셀 패딩을 -1 값으로 설정해야하거나 그렇지 않으면 인쇄 된 시트의 각 데이터 행 사이에 너무 많은 공간이있었습니다. 그러나, 나는 지금 국경 (특히 pdf 파일에)을 추가하려고 노력하고있다. 그리고 세포는 텍스트와 일렬로 나란히 서 있지 않다. 각 셀의 아래쪽 경계선은 텍스트를 통해 직접 자릅니다. 셀 패딩이 2 이상으로 설정된 경우 텍스트를 실제로 둘러 쌉니다.iText 셀 테두리 텍스트를 자르다
Document document = new Document();
Paragraph paragraph = new Paragraph();
Font iTextFont = new Font(Font.TIMES_ROMAN, 9, Font.NORMAL);
try{
PdfWriter.getInstance(document, new FileOutputStream("C:/datafiles/TestiText.pdf"));
document.open();
Table table = new Table(3);
table.setPadding(-1);
table.setWidth(90);
Cell cell1 = new Cell();
cell1.setBorder(Rectangle.BOX);
cell1.setVerticalAlignment(ElementTags.ALIGN_TOP);
table.setDefaultCell(cell1);
paragraph = new Paragraph("header", iTextFont);
Cell cell = new Cell(paragraph);
cell.setHeader(true);
cell.setColspan(3);
table.addCell(cell);
paragraph = new Paragraph("example cell", iTextFont);
table.addCell(paragraph);
paragraph = new Paragraph("one", iTextFont);
table.addCell(cell);
paragraph = new Paragraph("two", iTextFont);
cell = new Cell(paragraph);
table.addCell(paragraph);
paragraph = new Paragraph("Does this start a new row?", iTextFont);
table.addCell(paragraph);
paragraph = new Paragraph("Four", iTextFont);
table.addCell(paragraph);
paragraph = new Paragraph("Five", iTextFont);
table.addCell(paragraph);
document.add(table);
} catch (Exception e) {
//handle exception
}
document.close();
}
중 하나 (텍스트 배치에 영향을주지 않고) 한 방울을 전체 경계를 아래로 이동하여이 문제를 해결하기 위해, 또는 사이의 공간을 제거하는 방법은 무엇입니까 : 아래는 내가 뭐하는 거지의 샘플입니다 셀 패딩을 -1로 설정하지 않고 각 행 (공백은 텍스트 위의 문제 일뿐, 아래가 아님)
해결 방법을 찾으셨습니까? 나는 똑같은 문제를 겪고있다. 나는 패딩에 기인 한 것으로 보이지만, 패딩을 줄이면 텍스트가 아래쪽 경계를 자른다. –
신경 쓰지 마세요, 저는 PdfPTable로 전환했습니다. 이제 괜찮습니다. PDF 만 생성하기 때문에이 솔루션으로 충분합니다. –
가져온 라이브러리를 Java에 추가하십시오. java를 구현하기 위해 "전체 클래스 제공" – shareef