Table AutoFit in combination with cell padding and cell new line is not working properly

Hello,

When we are using TableAutoFit,cell padding and cell new line, the table is not fully autofitted.

If you run the following code you could see that the last 3 columns of the inner table could shrink a little more to fit into the 50% column width.

I believe that Aspose.Pdf when autofits the cells that contain textFragment with new line it takes into consideration the length of the text, not the length of the rendered text.

using System;

using Aspose.Pdf;

using Aspose.Pdf.Text;

namespace Reproducer

{

public class Program

{

public static void Main(string[] args)

{

//Instantiate Pdf document object

var pdf = new Document();

var margin = new MarginInfo() { Left = 1, Right = 5 };

var page = pdf.Pages.Add();

page.SetPageSize(PageSize.PageLetter.Height, PageSize.PageLetter.Width);

//Create a table

var table = new Table();

table.DefaultCellTextState = new TextState { FontSize = 5 };

[//table.ColumnAdjustment](https://table.columnadjustment/) = ColumnAdjustmentType.AutoFitToContent;

table.ColumnWidths = “50% 50%”;

//Add the table into the paragraphs collection of section

page.Paragraphs.Add(table);

var row = table.Rows.Add();

var cell = new Cell();

[//cell.Paragraphs.Add](https://cell.paragraphs.add/)(CreateTable(3, 10));

cell.Paragraphs.Add(CreateTable());

row.Cells.Add(cell);

cell =row.Cells.Add(“This should be second cell and be 5%”);

cell.Margin = margin;

pdf.Save(“Hello.pdf”);

}

public static Table CreateTable()

{

var margin = new MarginInfo() { Left = 1, Right = 5 };

var table = new Table {ColumnAdjustment = ColumnAdjustment.AutoFitToContent};

table.DefaultCellTextState = new TextState {FontSize = 5};

table.DefaultCellBorder = new BorderInfo(BorderSide.All);

var row = table.Rows.Add();

row.Cells.Add(“Ticker”);

var cell = new Cell();

cell.Paragraphs.Add(new TextFragment(“Hello”));

cell.Margin = margin;

row.Cells.Add(cell);

cell = new Cell();

cell.Paragraphs.Add(new TextFragment(“Port. " + Environment.NewLine + " Ending” + Environment.NewLine + " Weight"));

cell.Margin = margin;

row.Cells.Add(cell);

cell = new Aspose.Pdf.Cell();

cell.Paragraphs.Add(new TextFragment(“Port. “+ Environment.NewLine + " Ending” + Environment.NewLine + " Weight”));

cell.Margin = margin;

row.Cells.Add(cell);

cell = new Aspose.Pdf.Cell();

cell.Paragraphs.Add(new TextFragment(“Bench. " + Environment.NewLine + " Ending” + Environment.NewLine + " Weight"));

cell.Margin = margin;

row.Cells.Add(cell);

row = table.Rows.Add();

cell = new Cell();

cell.Paragraphs.Add(new TextFragment(“XOM”));

cell.Margin = margin;

row.Cells.Add(cell);

var cell1 = row.Cells.Add("Exxon Mobil Corporation is a company ");

cell1.Margin = new MarginInfo() {Left = 40, Right = 5};

cell = row.Cells.Add(“2.13”);

cell.Margin = margin;

cell =row.Cells.Add(“1.91”);

cell.Margin = margin;

cell =row.Cells.Add(“0.22”);

cell.Margin = margin;

return table;

}

}

}

Hi Daniel,


Thanks for your inquriy. I have tested the scenario and noticed the reported issue, so logged a ticket PDFNET-41106 in our issue tracking system for further investigation and rectification. We will notify you as soon as issue is resolved.

We are sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNET-41106) have been fixed in Aspose.Pdf for .NET 16.10.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Upgraded to latest version and issue is fixed.

Thank you.
Hi,

Thanks for the acknowledgement.

We are glad to hear that your problem is resolved. Please continue using our API's and in the event of any further query, please feel free to contact.