【问题标题】:Boxable if cell height is changed text don't appear如果单元格高度发生更改,则可装箱文本不会出现
【发布时间】:2020-05-06 20:13:20
【问题描述】:

我根据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);

单元格中没有绘制内容

我尝试更改行高、更改字体大小,但没有帮助。

你知道怎么解决吗?

【问题讨论】:

    标签: java pdfbox boxable


    【解决方案1】:

    经过一些调试,我注意到可以像这样更改单元格高度:

    cell.setHeight(cell.getTextHeight() + 0.5f);
    

    重要的是选择cell.getTextHeight(),然后添加你的值,如果你只输入一些像 12f 这样的数字,它将不起作用

    【讨论】:

      猜你喜欢
      • 2014-12-24
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      • 1970-01-01
      • 2012-04-11
      相关资源
      最近更新 更多