我正在使用 java 库 iText 来生成 pdf。问题是:如何在这样的 itext 表中定义单元格间距。
先感谢您!
PS:这是我的代码的一部分:
private static PdfPTable createFirstTable() throws DocumentException, IOException {
PdfPTable table = new PdfPTable(13);
BaseFont baseFont = BaseFont.createFont("times.ttf", BaseFont.IDENTITY_H, true);
Font deckFont = new Font(baseFont, 12f);
deckFont.setColor(BaseColor.RED);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
table.getDefaultCell().setPaddingBottom(15);
table.getDefaultCell().setPaddingTop(15);
Font deckFont1 = new Font(baseFont, 12f);
deckFont1.setColor(BaseColor.BLACK);
for (int i = 0; i < 4; i++) {
switch (i) {
case 0:
for (int j = 0; j < 13; j++) {
switch (j) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
table.addCell(new Paragraph(String.valueOf(j+2+"\u2666"),deckFont));
break;
case 8:
table.addCell(new Paragraph(String.valueOf(j+2+"\u2666"),deckFont));
break;
case 9:
table.addCell(new Paragraph(String.valueOf("J"+"\u2666"),deckFont));
break;
case 10:
table.addCell(new Paragraph(String.valueOf("D"+"\u2666"),deckFont));
break;
case 11:
table.addCell(new Paragraph(String.valueOf("K"+"\u2666"),deckFont));
break;
case 12:
table.addCell(new Paragraph(String.valueOf("A"+"\u2666"),deckFont));
break;
default:
table.addCell("Error case");
;
break;
}
}
table.completeRow();
break;
case 1:
for (int j = 0; j < 13; j++) {
switch (j) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
table.addCell(new Paragraph(String.valueOf(j+2+"\u2660"),deckFont1));
break;
case 8:
table.addCell(new Paragraph(String.valueOf(j+2+"\u2660"),deckFont1));
break;
case 9:
table.addCell(new Paragraph(String.valueOf("J"+"\u2660"),deckFont1));
break;
case 10:
table.addCell(new Paragraph(String.valueOf("D"+"\u2660"),deckFont1));
break;
case 11:
table.addCell(new Paragraph(String.valueOf("K"+"\u2660"),deckFont1));
break;
case 12:
table.addCell(new Paragraph(String.valueOf("A"+"\u2660"),deckFont1));
break;
default:
System.out.println("Error case");
break;
}
}