We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

CellBorders are causing tables to expand past the Table.ColumnWidths

Hi,


I’ve found an issue using Table.ColumnWidths and cell borders in the Aspose.pdf namespace. It looks like cell borders are not taken into account properly with column widths and seems to happen with both percentages and length values. This can cause the table to expand past the page margins and not fit like expected onto the page. Here is a reproducer:

static void generateTableWithAsposePdf()
{
var pdfDoc = new Aspose.Pdf.Document();
var page = pdfDoc.Pages.Add();
page.SetPageSize(612, 792);
page.PageInfo.Margin = new MarginInfo(27, 27, 27, 27);
var table = new Aspose.Pdf.Table();
table.ColumnWidths = “25% 25% 25% 25%”;
table.DefaultCellPadding = new Aspose.Pdf.MarginInfo(1.44, 1.44, 1.44, 1.44);
table.Border = new BorderInfo(BorderSide.All, 1, Color.Black);

for (int i = 0; i < 10; ++i)
{
var row = table.Rows.Add();

for (int j = 0; j <= 3; ++j)
{
row.Cells.Add(j.ToString());
}
}

var table2 = new Aspose.Pdf.Table();
table2.ColumnWidths = “25% 25% 25% 25%”;
table2.Border = new BorderInfo(BorderSide.All, 1, Color.Black);
table2.DefaultCellPadding = new Aspose.Pdf.MarginInfo(1.44, 1.44, 1.44, 1.44);
table2.DefaultCellBorder = new BorderInfo(BorderSide.All, 1, Color.Black);

for (int i = 0; i < 10; ++i)
{
var row = table2.Rows.Add();

for (int j = 0; j <= 3; ++j)
{
row.Cells.Add(j.ToString());
}
}

page.Paragraphs.Add(table);
page.Paragraphs.Add(table2);
pdfDoc.Save(“asposepdfnamespace.pdf”);
}

static void generateTableWithGenerator()
{
//Instntiate the Pdf object by calling its empty constructor
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

//Create the section in the Pdf object
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
sec1.PageInfo.PageWidth = 612;
sec1.PageInfo.PageHeight = 792;

//Create MarginInfo object and set its left, bottom, right and top margins
Aspose.Pdf.Generator.MarginInfo margin = new Aspose.Pdf.Generator.MarginInfo();
margin.Top = 27;
margin.Left = 27;
margin.Right = 27;
margin.Bottom = 27;
sec1.PageInfo.Margin = margin;

Aspose.Pdf.Generator.MarginInfo padding = new Aspose.Pdf.Generator.MarginInfo();
padding.Top = 1.44F;
padding.Left = 1.44F;
padding.Right = 1.44F;
padding.Bottom = 1.44F;

//Instantiate a table object
Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();
tab1.ColumnWidths = “25% 25% 25% 25%”;
tab1.DefaultCellPadding = padding;

tab1.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 0.1F);

//Set table border using another customized BorderInfo object
tab1.Border = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 1);

for (int i = 0; i < 10; ++i)
{
var row = tab1.Rows.Add();

for (int j = 0; j <= 3; ++j)
{
row.Cells.Add(j.ToString());
}
}

//Instantiate a table object
Aspose.Pdf.Generator.Table tab2 = new Aspose.Pdf.Generator.Table();
tab2.ColumnWidths = “25% 25% 25% 25%”;
tab2.DefaultCellPadding = padding;
//Set table border using another customized BorderInfo object
tab2.Border = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 1);

for (int i = 0; i < 10; ++i)
{
var row = tab2.Rows.Add();

for (int j = 0; j <= 3; ++j)
{
row.Cells.Add(j.ToString());
}
}

//Add the table in paragraphs collection of the desired section
sec1.Paragraphs.Add(tab2);
sec1.Paragraphs.Add(tab1);
pdf1.Save(“generatornamespace.pdf”);
}

Hi Daniel,

Thanks for your inquiry. I have tested your scenario with shared document using Aspose.Pdf for .NET 11.5.0 and managed to observe the reported issue. For further investigation, I have logged an issue in our issue tracking system as PDFNEWNET-40582 and also linked your request to it. We will keep you updated via this thread regarding the issue status.

We are sorry for the inconvenience caused.

<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:
Calibri;color:#333333;mso-ansi-language:EN-US;mso-fareast-language:EN-US;
mso-bidi-language:AR-SA”>Best Regards,

The issues you have found earlier (filed as PDFNEWNET-40582) have been fixed in Aspose.Pdf for .NET 11.6.0.


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

Hi,


I tested out the latest version 11.6.0, and I’m still running into the issue with the test cases I initially gave above. It still gives the same result as 11.5.0. The cell borders in the Aspose.Pdf namespace still go past the right page margin while the old Aspose.Pdf.Generator namespace doesn’t.

Hi Daniel,


We are sorry for the inconvenience. Please note by default borders does not included in column width, please set IsBordersIncluded property to true, it will resolve the issue.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal,


I tried searching for the IsBordersIncluded property, but I couldn’t find it in any of your documentation in the Aspose.Pdf namespace. Which one of your objects contains this property?

Hi,


Thanks for contacting support and sorry for the delayed response. In order to resolve earlier reported issue, please try using following code snippet. For your reference, I have also attached the output generated over my end.

[C#]

var pdfDoc = new Aspose.Pdf.Document();<o:p></o:p>

var page = pdfDoc.Pages.Add();

page.SetPageSize(612, 792);

page.PageInfo.Margin = new Aspose.Pdf.MarginInfo(27, 27, 27, 27);

var table = new Aspose.Pdf.Table();

table.ColumnWidths = "25% 25% 25% 25%";

table.DefaultCellPadding = new Aspose.Pdf.MarginInfo(1.44, 1.44, 1.44, 1.44);

table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1, Aspose.Pdf.Color.Black);

for (int i = 0; i < 10; ++i)

{

var row = table.Rows.Add();

for (int j = 0; j <= 3; ++j)

{

row.Cells.Add(j.ToString());

}

}

var table2 = new Aspose.Pdf.Table();

table2.ColumnWidths = "25% 25% 25% 25%";

table2.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1, Aspose.Pdf.Color.Black);

table2.DefaultCellPadding = new Aspose.Pdf.MarginInfo(1.44, 1.44, 1.44, 1.44);

table2.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1, Aspose.Pdf.Color.Black);

table2.IsBordersIncluded = true;

for (int i = 0; i < 10; ++i)

{

var row = table2.Rows.Add();

for (int j = 0; j <= 3; ++j)

{

row.Cells.Add(j.ToString());

}

}

page.Paragraphs.Add(table);

page.Paragraphs.Add(table2);

pdfDoc.Save("c:/pdftest/asposepdfnamespace.pdf");