RowFormat setAllowAutoFit can not work as expected

Hi Dragos,

Thanks for your inquiry.

You can fix these issues by removing the call to updateTableLayout. Of course this becomes confusing as the other bug reported by you is fixed for the time being by using this method.

The updateTableLayout method is not normally called at all, it completely rebuilds the layout of tables which can sometimes lead to some of them becoming screwed up. It’s only really called in certain times where table layout seems to be outdated. Therefore it can’t be used all the time or else some existing tables that look correct may break.

For now, hopefully these issues occur in different documents so you can either use this method if it helps or not, otherwise I’m afraid you may have to wait until the issue is properly fixed. We will keep you informed of any developments.

Thanks,

Also in response to your questions:

  • If you remove the calls to updateTableLayout then the second table will resize properly regardless of the presense of the first table or not. I have logged this as an issue.
  • The reason why the preferred width on the cell is not showing up is because you auto fit the table to window which clears all preferred widths on cells. If you remove this line then the cell appears as it should.

Thanks,

Hi Dragos,

You definitely should stop calling docBuilder.getDocument().updateTableLayout();

It is not helping in your case and in fact, causing problems.

For your testtable_singlecell example if you just remove the call to updateTableLayout() it all works fine.

For your testIncorectResize you need to remove both calls to updateTableLayout(). It also looks like you need to remove both calls to table.setAllowAutoFit( true); but it is hard for me to advice because I don’t fully understand what sort of table you want to create. If you describe how it should look like, then our support will provide your a code example how to do that.

The reason you need to remove calls to updateTableLayout is that this method is used only to “correct” layout of tables that already exist in the document and their internal structures are slightly “out of sync”. This is only needed in rare cases, definitely not when you are creating a table using document builder.

The reason you need to remove setAllowAutoFit(true) for the first table is that you specify width of the cells explicitly in points. Having autofit enabled and explicit width in points is somewhat contradictory. While it works okay, it is confusing and I don’t understand what you want your table to look like.

The reason you need to remove setAllowAutoFit(true) for the second table, is that you invoke table.autoFit for this table already and specify the option you want. So again it is a double take and confusing. Although the table looks alright I think.

Hey Roman,

I have added the updateTable call because to fix other issues with tables in PDF. See here for details:
https://forum.aspose.com/t/hyperlinks-in-tables-break-resizing-algorithms-for-pdf-output/57467

So removing the call to updateTable without a fix from Aspose will just mean I’m trading one bug for another.

Regards,
Dragos

Hi Dragos,

Thank you for additional information. As another workaround of the issue mentioned in the thread you mentioned, you can try specifying a fixed column width. This should resolve the problem.

Best regards,

Hey Alexey,

setting the column width defeats the very purpose of “autofit”. And it’s not even possible since you cannot always tell which of the columns will have the biggest content.

Regards,
Dragos

Hi

Thank you for additional information. Currently I cannot suggest you any way to work this problem around. You should just wait for the fix of the original issue.

Best regards,

The issues you have found earlier (filed as WORDSNET-5325) have been fixed in this .NET update and this Java update.