Hi,
with Aspose.Words 10.x and Aspose.Words 11 using table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW) results in the table being resized to fit the page widths. But the result is very different from what you would get in Microsoft Word as it seems that the resize doesnt take into account the preferred widths of the column but only their content.
Using table.setPreferredWidth(PreferredWidth.fromPercent(100)) however yields results closer to Word’s functionality.
My questions are:
1. is is safe to use table.setPreferredWidth(PreferredWidth.fromPercent(100)) as the mean to achieve autofit to window?
2. what is the difference between using the two methofs?
Thanks and regards,
Dragos
Hi Dragos,
Thanks for your query. I have not found any problem with AutoFitBehavior.AUTO_FIT_TO_WINDOW. It would be great, If you share your document for investigation purposes.
Here is what you can do to reproduce it:
1. create a table with 1 row and 3 cells
2. in each cell set the content to be a single word, for example Aspose
3. set the first cell width to 50pts, the second to 100pts and the third’s to 150pts
4. set the table’s autofit to window
Result: a table occupying the whole page width and with 3 identically sized columns.
To see the expected results do steps 1-4 in Word or steps 1-3 in Aspose and just step 4 in Word.
Regards,
Dragos
Hi Dragos,
Thanks for sharing the further information. Yes, the three cells will become identical width after calling autoFit method. You can set the width of each cell after using autoFit method. Please see the code below and please read following documentation link for your kind reference.
table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW);
cell1.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(50));
cell2.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(100));
cell3.getCellFormat().setPreferredWidth(PreferredWidth.fromPoints(150));
Hi Dragos,
Thanks to both of you, very useful answers.
@Tahir - setting the autofit behavior before setting the preferred widths works on Word ( with a couple of minor glitches) but on PDF the columns have identical sizes
@Adam - thanks for the heads up about the sum of columns vs the page width. And again, just like using the autofit method, the results on PDF are slightly different than the Word ones. Still they seem better than what you get using autofit.
Regards,
Dragos
Hi Dragos,
Thanks for sharing the information. It would be great, If you share your documents and code for investigation purposes.