Cell setFitWidth method does not work

Hi support,

Please note that the setFitWidth() method does not work when is used on cells. You can check this with the following code:

Pdf pdf = new Pdf();
Section sec1 = pdf.getSections().add();
Table table = new Table(sec1);
Row row1 = new Row(table);
table.getRows().add(row1);
Cell cell11 = new Cell(row1);
cell11.setFitWidth(10);
Text text1 = new Text(sec1, “some text”);
BorderInfo border = new BorderInfo();
border.setBorderSide(BorderSide.All);
GraphInfo gr = new GraphInfo();
gr.setLineStyle(LineStyleType.Solid);
gr.setLineWidth(2);
border.setAll(gr);
cell11.setBorder(border);
cell11.getParagraphs().add(text1);
row1.getCells().add(cell11);
Cell cell12 = new Cell(table, “some more text”);
cell12.setBorder(border);
row1.getCells().add(cell12);
Row row2 = new Row(table);
table.getRows().add(row2);
Cell cell21 = new Cell(row2, “another some text”);
cell21.setBorder(border);
cell21.setFitWidth(10);
row2.getCells().add(cell21);
Cell cell22 = new Cell(table, “another some more text”);
cell22.setBorder(border);
row2.getCells().add(cell22);
sec1.getParagraphs().add(table);
pdf.save(new FileOutputStream(new File(“C:/Temp/CellWidthIssue.pdf”)));

I guess that the cell width must be the same within the same column. There is a method for the table object “setColumnWidths”, but it requires values for every column.

Best regards,
Milan

Hello Milan,

I have attested to the issue and have noticed the same problem. The issue has been communicated to the development team, and they are looking into the details of this matter. Soon you will be updated with the status of the correction.

We apologize for your inconvenience.

Hi Milan,

You are right. Cell.setFitWidth() is not supported in the current version, you have to use the Table.setColumnWidths() to specify the cell’s width. If you don’t call the table’s setColumnWidths(), the table will automatically span to the width of the page and every column has the same width.

Thank you for using our product.

<o:shapelayout v:ext=“edit”>
<o:idmap v:ext=“edit” data=“1”/>
</o:shapelayout><![endif]–>

Hi Sandy.Zhang,

When handling hundreds of tables, the time to calculate&set the widths for every column in every table is quite significant at runtime. I think that the performance could improve significantly if it would be possible to set the width only for the column that requires having its width modified. If this could be accomplished by setting the width for a single cell within that column (this maybe requires that the maximum width set for a cell within a column is taken into consider), then it could make the whole process even more fast.

Anyway, please mention if the above solution is relevant and if it can justify the effort to be implemented in the future.

I'm not sure if all this means just moving some explicit coding to be executed in the background, on your side. If so, then it's obvious that the things must remain on this issue as they are.

Regards,
Milan

Hello Milan,

After going through your requirement of reconsidering the deprecated method Cell.setFitWidth() I've discussed it with development team and I sorry to inform you that it would not be feasible for us to reconsider the implementation of this feature. You would have to use Table.setColumnWidths() instead. We apologize for your inconvenience.

Your understanding is greatly appreciated in this regard.