【发布时间】:2016-09-11 19:48:02
【问题描述】:
我正在使用 iText 创建带有表格的 PDF。表格标题有 90 度旋转的文本,我使用 CellEvent 添加它(代码如下)。这很好用,除非表格跨越多个页面时,旋转的单元格标题文本会从页面顶部流出。
我试过设置 cell.setFixedHeight(100) 但它似乎不影响单元格。我也尝试过this solution,但我根本无法让单元格显示带有文本的结果图像。
@Override
public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
PdfContentByte canvas = canvases[PdfPTable.TEXTCANVAS];
try {
canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, false), this.fontSize);
} catch (DocumentException | IOException e) {
e.printStackTrace();
}
if (this.alignment == PdfPCell.ALIGN_CENTER) {
this.left = ((position.getRight() - position.getLeft()) / 2 );
}
else if (this.alignment == PdfPCell.ALIGN_MIDDLE) {
this.top = ((position.getTop() - position.getBottom()) / 2 );
}
canvas.showTextAligned(this.alignment, this.text, position.getLeft() + this.left, position.getTop() - this.top, this.rotation);
}
这是单元格标题溢出的样子。在此示例中,它应该显示月份和年份(2016 年 3 月)。
我想让单元格的高度取决于所使用的实际标题文本。关于如何解决这个问题的任何想法?
【问题讨论】: