我根据https://github.com/dhorions/boxable/wiki中的示例创建了BaseTable
float margin = 50;
float yStartNewPage = myPage.getMediaBox().getHeight() - (2 * margin);
float tableWidth = myPage.getMediaBox().getWidth() - (2 * margin);
boolean drawContent = true;
float yStart = yStartNewPage;
float bottomMargin = 70;
float yPosition = 550;
BaseTable table = new BaseTable(yPosition, yStartNewPage, bottomMargin, tableWidth, margin, mainDocument, myPage, true, drawContent);
Row<PDPage> headerRow = table.createRow(15f);
Cell<PDPage> cell = headerRow.createCell(100, "Header");
table.addHeaderRow(headerRow);
Row<PDPage> row = table.createRow(12);
cell = row.createCell(30, "Data 1");
cell = row.createCell(70, "Some value");
table.draw();
contentStream.close();
mainDocument.addPage(myPage);
mainDocument.save("testfile.pdf");
mainDocument.close();桌子看起来没问题

但是当我想像这样改变单元格高度时
cell.setHeight(5f);
未在单元格中绘制内容

我试着改变行高,改变字体大小,但是没有帮助。
你知道怎么修吗?
发布于 2020-02-18 04:20:08
经过一些调试后,我注意到单元格的高度可以像这样改变:
cell.setHeight(cell.getTextHeight() + 0.5f);选择cell.getTextHeight(),然后添加你的值是很重要的,如果你只放一个像12f这样的数字,它不会起作用
https://stackoverflow.com/questions/59829724
复制相似问题