我正在使用 iText 7.0.0(Java 风格),似乎表格单元格 HorizontalAlignment 被忽略了,因为 CENTER 和 RIGHT 都不起作用。你能重现这个吗?
以及重现的代码:
private static void brokenTableCellHorizontalAlignmentPdf(OutputStream output) throws IOException {
PdfWriter writer = new PdfWriter(output);
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
PdfFont font = PdfFontFactory.createFont(FontConstants.HELVETICA);
Table table = new Table(new float[] {15f, 16f, 4f}).setWidthPercent(100);
for (int y = 1; y <= 3; ++y) {
for (int x = 1; x <= 3; ++x) {
table.addCell(
new Cell()
.setVerticalAlignment(VerticalAlignment.MIDDLE)
.setHorizontalAlignment(HorizontalAlignment.CENTER)
.add(new Paragraph(String.format("(%d, %d)%s", y, x, x == 1 ? "\n\ntest" : ""))
.setFont(font)
.setFontSize(8)));
}
}
document.add(table);
document.close();
}