我正在使用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月)。

我希望单元格的高度取决于正在使用的实际标题文本。有关如何解决这个问题的任何想法?

声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。