boxable icon indicating copy to clipboard operation
boxable copied to clipboard

Change cell height

Open zaqpiotr opened this issue 5 years ago • 6 comments

Hello Everyone,

I have created BaseTable according to example from https://github.com/dhorions/boxable/wiki


    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();

Table looks fine

image

but when I want change cell height like this

cell.setHeight(5f);

Content is not drawn in cell

image

I was trying with changing row height, font size change, but it didn't help.

Do You know how to fix it?

zaqpiotr avatar Jan 20 '20 19:01 zaqpiotr

Are you sure that your text size are not bigger than your cell height? You should always ask yourself that. Thanks for the code snippet ! I take this and make quick tests ..

Frulenzo avatar Oct 06 '20 05:10 Frulenzo

ohhh, it's a bug. I tried making bigger cell height where I am certain that the text would fit in but also didn't have better result.

setCellHeight.pdf

Definetly a bug.

Frulenzo avatar Oct 06 '20 05:10 Frulenzo

What I did to make cell higher cell.setHeight(cell.getTextHeight() + 12.0f);

zaqpiotr avatar Oct 06 '20 06:10 zaqpiotr

oh wow. That is very good. At least taking the text height and then increasing the cell height. Pretty clever :+1: When we go in other direction (making the cell height smaller), we need to reduce the font size first, possibly the cell paddings also and then setting the height lower than former cell's text height.

Frulenzo avatar Oct 06 '20 07:10 Frulenzo

Hey, is there any news about this issue? I need fixed row sizes (height & width) in my project, so this issue is directly effecting me. Thanks a lot!

stefanm96 avatar Mar 03 '21 10:03 stefanm96

Hello, I also should work with lower Cell-hight or padding. Do you know a workaround to get a compact table? Thank you for helping! Joseph

jsail avatar Apr 03 '22 01:04 jsail