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に追加してください。私はあなたに "完全なクラスを提供する" – shareef