iTextを使用して、テーブルを含むpdfまたはrtfファイルを生成するプログラムを作成しています。どちらのファイルも最後に生成できるように、より具体的な RtfTable や pdfTable ではなく、iText クラスのテーブルとセルを使用しました。セルのパディングを -1 の値に設定する必要がありました。そうしないと、印刷されたシートのデータの各行の間にスペースがありすぎました。ただし、境界線を (特に pdf ファイルに) 追加しようとしていますが、セルがテキストと並んでいません。各セルの下枠は、テキストを直接切り取ります。セルのパディングが 2 以上に設定されている場合にのみ、実際にテキストが囲まれます。以下は私がやっていることのサンプルです:
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 に設定せずに?