Border has extra width when using ColumnSpan

Hi! I have an issue with the border having extra width when using ColumnSpan. The version of Aspose I am using is 8.0. I have attached the resulting PDF. Here is the code:


public static void BordrExtraWidth()
{
Pdf pdf = new Pdf();
pdf.CompressionLevel = 6;
Section section = new Section(pdf);
pdf.Sections.Add(section);

section.Paragraphs.Add(new Text(“In all tables below, the LineWidth of the Top border is always specified as 2. #$NL” +
“We can also see that the right border overlaps the top border which is pretty ugly/annoying. #$NL " +
“When the thick border appears, look closely and you will see it overlaps on the left. #$NL #$NL”));

section.Paragraphs.Add(new Text(“Column span of 4”));
Table table = new Table();
table.ColumnWidths = “10% 20% 10% 5% 10% 20% 10% 5% 10%”;
table.RepeatingRows = 2;
Row row = table.Rows.Add();
AddCellWithBackgroundAndBorder(row, “Year”, rowSpan: 2);
AddCellWithBackgroundAndBorder(row, “3/4 thin border”, colSpan: 4);
AddCellWithBackgroundAndBorder(row, “Thick border! Why?”, colSpan: 4);

row = table.Rows.Add();
AddCellWithBackgroundAndBorder(row, “1-1”);
AddCellWithBackgroundAndBorder(row, “1-2”);
AddCellWithBackgroundAndBorder(row, “1-3”);
AddCellWithBackgroundAndBorder(row, “1-4”);
AddCellWithBackgroundAndBorder(row, “2-1”);
AddCellWithBackgroundAndBorder(row, “2-2”);
AddCellWithBackgroundAndBorder(row, “2-3”);
AddCellWithBackgroundAndBorder(row, “2-4”);

row = table.Rows.Add();
AddCell(row, “2013”);
AddCell(row, “2.0”);
AddCell(row, “2.1”);
AddCell(row, “2.2”);
AddCell(row, “2.3”);
AddCell(row, “3.0”);
AddCell(row, “3.1”);
AddCell(row, “3.2”);
AddCell(row, “3.3”);
section.Paragraphs.Add(table);

section.Paragraphs.Add(new Text(”#$NL #$NL"));

section.Paragraphs.Add(new Text(“Column span of 3 with white divisions”));
table = new Table();
table.ColumnWidths = “10% 5% 20% 10% 10% 5% 20% 10% 10%”;
table.RepeatingRows = 2;
row = table.Rows.Add();
AddCellWithBackgroundAndBorder(row, “Year”, rowSpan: 2);
AddCellWithBackgroundAndBorder(row, “”, rowSpan: 2, backgroundColor: new Color(“White”));
AddCellWithBackgroundAndBorder(row, “Thin border”, colSpan: 3);
AddCellWithBackgroundAndBorder(row, “”, backgroundColor: new Color(“White”));
AddCellWithBackgroundAndBorder(row, “Thick border on half!?”, colSpan: 3);

row = table.Rows.Add();
AddCellWithBackgroundAndBorder(row, “1-1”);
AddCellWithBackgroundAndBorder(row, “1-2”);
AddCellWithBackgroundAndBorder(row, “1-3”);
AddCellWithBackgroundAndBorder(row, “”, backgroundColor: new Color(“White”));
AddCellWithBackgroundAndBorder(row, “2-1”);
AddCellWithBackgroundAndBorder(row, “2-2”);
AddCellWithBackgroundAndBorder(row, “2-3”);

row = table.Rows.Add();
AddCell(row, “2013”);
AddCell(row, “”, couleur: new Color(“White”));
AddCell(row, “2”);
AddCell(row, “3”);
AddCell(row, “3.1”);
AddCell(row, “”, couleur: new Color(“White”));
AddCell(row, “4”);
AddCell(row, “5”);
AddCell(row, “5.1”);
section.Paragraphs.Add(table);

section.Paragraphs.Add(new Text("#$NL #$NL"));

section.Paragraphs.Add(new Text(“Column span of 2 with white divisions”));
table = new Table();
table.ColumnWidths = “10% 5% 20% 20% 5% 20% 20%”;
table.RepeatingRows = 2;
row = table.Rows.Add();
AddCellWithBackgroundAndBorder(row, “Year”, rowSpan: 2);
AddCellWithBackgroundAndBorder(row, “”, rowSpan: 2, backgroundColor: new Color(“White”));
AddCellWithBackgroundAndBorder(row, “Thin border”, colSpan: 2);
AddCellWithBackgroundAndBorder(row, “”, backgroundColor: new Color(“White”));
AddCellWithBackgroundAndBorder(row, “Finally lost some weight”, colSpan: 2);

row = table.Rows.Add();
AddCellWithBackgroundAndBorder(row, “1-1”);
AddCellWithBackgroundAndBorder(row, “1-2”);
AddCellWithBackgroundAndBorder(row, “”, backgroundColor: new Color(“White”));
AddCellWithBackgroundAndBorder(row, “2-1”);
AddCellWithBackgroundAndBorder(row, “2-2”);

row = table.Rows.Add();
AddCell(row, “2013”);
AddCell(row, “”, couleur: new Color(“White”));
AddCell(row, “2”);
AddCell(row, “3”);
AddCell(row, “”, couleur: new Color(“White”));
AddCell(row, “4”);
AddCell(row, “5”);
section.Paragraphs.Add(table);

section.Paragraphs.Add(new Text("#$NL #$NL"));

section.Paragraphs.Add(new Text(“Column span of 2”));
table = new Table();
table.ColumnWidths = “10% 20% 25% 20% 25%”;
table.RepeatingRows = 2;
row = table.Rows.Add();
AddCellWithBackgroundAndBorder(row, “Year”, rowSpan: 2);
AddCellWithBackgroundAndBorder(row, “Thin border”, colSpan: 2);
AddCellWithBackgroundAndBorder(row, “Thick border on half?!”, colSpan: 2);

row = table.Rows.Add();
AddCellWithBackgroundAndBorder(row, “1-1”);
AddCellWithBackgroundAndBorder(row, “1-2”);
AddCellWithBackgroundAndBorder(row, “2-1”);
AddCellWithBackgroundAndBorder(row, “2-2”);

row = table.Rows.Add();
AddCell(row, “2013”);
AddCell(row, “2”);
AddCell(row, “3”);
AddCell(row, “4”);
AddCell(row, “5”);
section.Paragraphs.Add(table);

string filename = @“d:\BordrExtraWidth.pdf”;
pdf.Save(filename);
Process.Start(filename);
}

private static void AddCellWithBackgroundAndBorder(Row row, string text, int colSpan = 1, int rowSpan = 1, Color backgroundColor = null)
{
Cell c = row.Cells.Add();
c.BackgroundColor = backgroundColor ?? new Color(77, 108, 130);
c.RowSpan = rowSpan;
c.ColumnsSpan = colSpan;

c.Border = new BorderInfo()
{
Right = new GraphInfo() { LineWidth = 1, Color = new Color(“White”) },
Top = new GraphInfo() { LineWidth = 2, Color = new Color(“White”) },
};

c.Paragraphs.Add(new Text(text));
}

private static Cell AddCell(Row row, string text, int colSpan = 1, int rowSpan = 1, Color couleur = null)
{
Cell cell = row.Cells.Add(text); cell.RowSpan = rowSpan; cell.ColumnsSpan = colSpan;
if (couleur != null)
{
cell.BackgroundColor = couleur;
}
return cell;
}

Thanks,

Jean-François Rouleau

Hi there,


Thanks for your inquiry. I've managed to reproduce the issue at my end and logged it as PDFNEWNET-35320 in our bug tracking system for further investigation and resolution. You will be notified via this thread as soon as it is resolved.


Sorry for the inconvenience faced.


Best Regards,

Hi,


Thanks for your patience.

I am pleased to share that the issue reported earlier has been resolved. Please try using the following code snippet based on new DOM approach to generate correct output. For your reference, I have also attached the resultant PDF generated over my end using upcoming release of Aspose.Pdf for .NET 8.2.0.

[C#]

string outFile = “c:/pdftest/TableBorderIssue.pdf”;<o:p></o:p>

Document doc = new Document();

Page page = doc.Pages.Add();

page.Paragraphs.Add(new TextFragment("In all tables below, the LineWidth of the Top border is always specified as 2. "));

page.Paragraphs.Add(new TextFragment("We can also see that the right border overlaps the top border which is pretty ugly/annoying."));

page.Paragraphs.Add(new TextFragment("When the thick border appears, look closely and you will see it overlaps on the left."));

page.Paragraphs.Add(new TextFragment(""));

page.Paragraphs.Add(new TextFragment(""));

page.Paragraphs.Add(new TextFragment("Column span of 4"));

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

table.ColumnWidths = "10% 20% 10% 5% 10% 20% 10% 5% 10%";

table.RepeatingRowsCount = 2;

Aspose.Pdf.Row row = table.Rows.Add();

AddCellWithBackgroundAndBorder(row, "Year", rowSpan: 2);

AddCellWithBackgroundAndBorder(row, "3/4 thin border", colSpan: 4);

AddCellWithBackgroundAndBorder(row, "Thick border! Why?", colSpan: 4);

row = table.Rows.Add();

AddCellWithBackgroundAndBorder(row, "1-1");

AddCellWithBackgroundAndBorder(row, "1-2");

AddCellWithBackgroundAndBorder(row, "1-3");

AddCellWithBackgroundAndBorder(row, "1-4");

AddCellWithBackgroundAndBorder(row, "2-1");

AddCellWithBackgroundAndBorder(row, "2-2");

AddCellWithBackgroundAndBorder(row, "2-3");

AddCellWithBackgroundAndBorder(row, "2-4");

row = table.Rows.Add();

AddCell(row, "2013");

AddCell(row, "2.0");

AddCell(row, "2.1");

AddCell(row, "2.2");

AddCell(row, "2.3");

AddCell(row, "3.0");

AddCell(row, "3.1");

AddCell(row, "3.2");

AddCell(row, "3.3");

page.Paragraphs.Add(table);

page.Paragraphs.Add(new TextFragment(""));

page.Paragraphs.Add(new TextFragment(""));

page.Paragraphs.Add(new TextFragment("Column span of 3 with white divisions"));

table = new Aspose.Pdf.Table();

table.ColumnWidths = "10% 5% 20% 10% 10% 5% 20% 10% 10%";

table.RepeatingRowsCount = 2;

row = table.Rows.Add();

AddCellWithBackgroundAndBorder(row, "Year", rowSpan: 2);

AddCellWithBackgroundAndBorder(row, "", rowSpan: 2, backgroundColor: Aspose.Pdf.Color.White);

AddCellWithBackgroundAndBorder(row, "Thin border", colSpan: 3);

AddCellWithBackgroundAndBorder(row, "", backgroundColor: Aspose.Pdf.Color.White);

AddCellWithBackgroundAndBorder(row, "Thick border on half!?", colSpan: 3);

row = table.Rows.Add();

AddCellWithBackgroundAndBorder(row, "1-1");

AddCellWithBackgroundAndBorder(row, "1-2");

AddCellWithBackgroundAndBorder(row, "1-3");

AddCellWithBackgroundAndBorder(row, "", backgroundColor: Aspose.Pdf.Color.White);

AddCellWithBackgroundAndBorder(row, "2-1");

AddCellWithBackgroundAndBorder(row, "2-2");

AddCellWithBackgroundAndBorder(row, "2-3");

row = table.Rows.Add();

AddCell(row, "2013");

AddCell(row, "", couleur: Aspose.Pdf.Color.White);

AddCell(row, "2");

AddCell(row, "3");

AddCell(row, "3.1");

AddCell(row, "", couleur: Aspose.Pdf.Color.White);

AddCell(row, "4");

AddCell(row, "5");

AddCell(row, "5.1");

page.Paragraphs.Add(table);

page.Paragraphs.Add(new TextFragment(""));

page.Paragraphs.Add(new TextFragment(""));

page.Paragraphs.Add(new TextFragment("Column span of 2 with white divisions"));

table = new Aspose.Pdf.Table();

table.ColumnWidths = "10% 5% 20% 20% 5% 20% 20%";

table.RepeatingRowsCount = 2;

row = table.Rows.Add();

AddCellWithBackgroundAndBorder(row, "Year", rowSpan: 2);

AddCellWithBackgroundAndBorder(row, "", rowSpan: 2, backgroundColor: Aspose.Pdf.Color.White);

AddCellWithBackgroundAndBorder(row, "Thin border", colSpan: 2);

AddCellWithBackgroundAndBorder(row, "", backgroundColor: Aspose.Pdf.Color.White);

AddCellWithBackgroundAndBorder(row, "Finally lost some weight", colSpan: 2);

row = table.Rows.Add();

AddCellWithBackgroundAndBorder(row, "1-1");

AddCellWithBackgroundAndBorder(row, "1-2");

AddCellWithBackgroundAndBorder(row, "", backgroundColor: Aspose.Pdf.Color.White);

AddCellWithBackgroundAndBorder(row, "2-1");

AddCellWithBackgroundAndBorder(row, "2-2");

row = table.Rows.Add();

AddCell(row, "2013");

AddCell(row, "", couleur: Aspose.Pdf.Color.White);

AddCell(row, "2");

AddCell(row, "3");

AddCell(row, "", couleur: Aspose.Pdf.Color.White);

AddCell(row, "4");

AddCell(row, "5");

page.Paragraphs.Add(table);

page.Paragraphs.Add(new TextFragment(""));

page.Paragraphs.Add(new TextFragment(""));

page.Paragraphs.Add(new TextFragment("Column span of 2"));

table = new Aspose.Pdf.Table();

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

table.RepeatingRowsCount = 2;

row = table.Rows.Add();

AddCellWithBackgroundAndBorder(row, "Year", rowSpan: 2);

AddCellWithBackgroundAndBorder(row, "Thin border", colSpan: 2);

AddCellWithBackgroundAndBorder(row, "Thick border on half?!", colSpan: 2);

row = table.Rows.Add();

AddCellWithBackgroundAndBorder(row, "1-1");

AddCellWithBackgroundAndBorder(row, "1-2");

AddCellWithBackgroundAndBorder(row, "2-1");

AddCellWithBackgroundAndBorder(row, "2-2");

row = table.Rows.Add();

AddCell(row, "2013");

AddCell(row, "2");

AddCell(row, "3");

AddCell(row, "4");

AddCell(row, "5");

page.Paragraphs.Add(table);

doc.Save(outFile);

private static void AddCellWithBackgroundAndBorder(Aspose.Pdf.Row row, string text, int colSpan = 1, int rowSpan = 1, Aspose.Pdf.Color backgroundColor = null)

{

Aspose.Pdf.Cell c = row.Cells.Add();

c.BackgroundColor = backgroundColor ?? Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(77, 108, 130));

c.RowSpan = rowSpan;

c.ColSpan = colSpan;

c.Border = new Aspose.Pdf.BorderInfo();

CellBorderStyle topStyle = new CellBorderStyle();

c.Border.Top = topStyle;

topStyle.LineWidth = 2;

topStyle.Color = Aspose.Pdf.Color.White;

CellBorderStyle rightStyle = new CellBorderStyle();

c.Border.Right = rightStyle;

rightStyle.LineWidth = 1;

rightStyle.Color = Aspose.Pdf.Color.White;

c.Paragraphs.Add(new TextFragment(text));

}

private static Aspose.Pdf.Cell AddCell(Aspose.Pdf.Row row, string text, int colSpan = 1, int rowSpan = 1, Aspose.Pdf.Color couleur = null)

{

Aspose.Pdf.Cell cell = row.Cells.Add(text); cell.RowSpan = rowSpan; cell.ColSpan = colSpan;

if (couleur != null)

{

cell.BackgroundColor = couleur;

}

return cell;

}

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


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