Table Cell borders not showing

I am attempting to set the top border of a specific cell (or cell with a columnspan) and the border doesn't seem to render at all. Any thoughts on why this doesn't work?

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

var row = new Aspose.Pdf.Generator.Row(table);
var cell = new Aspose.Pdf.Generator.Cell(row);

cell.Border = new Aspose.Pdf.Generator.BorderInfo();
cell.Border.SetBorderStyle((int)Aspose.Pdf.Generator.BorderSide.Top, Aspose.Pdf.Generator.BorderStyle.Double);
cell.Alignment = AlignmentType.Left;
cell.ColumnsSpan = 5;

var text = new Aspose.Pdf.Generator.Text("Stuff");
text.Margin.Bottom = 2;
text.Margin.Top = 2;
text.Margin.Right = 2;
text.Margin.Left = 2;
text.TextInfo.FontName = "Helvetica-Bold";
text.TextInfo.FontSize = 12;

cell.Paragraphs.Add(text);

row.Cells.Add(cell);

table.Rows.Add(row);

Hi Robbe,


Please try using the new Document Object Model (DOM) approach of Aspose.Pdf for .NET in order to generate table objects. For further details, please visit Working with Tables

We are sorry for this inconvenience.

I could not find a better way to make this work other than the following. Not exactly an intuitive object model...

var row = new Aspose.Pdf.Row();
var cell = new Aspose.Pdf.Cell();

cell.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
cell.Border.Right = null;
cell.Border.Left = null;

rmorris-1: I could not find a better way to make this work other than the following. Not exactly an intuitive object model…

var row = new Aspose.Pdf.Row();
var cell = new Aspose.Pdf.Cell();

cell.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
cell.Border.Right = null;
cell.Border.Left = null;

Hi Robbe,

In order to only create the top border of table cell, you can use Aspose.Pdf.BorderSide.Top enumeration value. Please take a look over the code snippet below which generates a table with two rows where the second row has only the top border with red color.

C#

Document doc = new Document();
doc.Pages.Add();

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

var row = new Aspose.Pdf.Row();
var cell = new Aspose.Pdf.Cell();

cell.Border = new Aspose.Pdf.BorderInfo();
cell.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
cell.ColSpan = 5;

Aspose.Pdf.Text.TextFragment text = new Aspose.Pdf.Text.TextFragment("Stuff");
text.Margin.Bottom = 2;
text.Margin.Top = 2;
text.Margin.Right = 2;
text.Margin.Left = 2;
text.TextState.Font = FontRepository.FindFont("Verdana");
text.TextState.FontSize = 12;
cell.Paragraphs.Add(text);

row.Cells.Add(cell);
table.Rows.Add(row);

var row2 = new Aspose.Pdf.Row();
var cell2 = new Aspose.Pdf.Cell();
cell2.Paragraphs.Add(new TextFragment("Second Row, Cell"));
row2.Cells.Add(cell2);
cell2.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Top, 0.5F, Aspose.Pdf.Color.Red);

cell2.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Top, 0.5F, Aspose.Pdf.Color.Red);
table.Rows.Add(row2);

doc.Pages[1].Paragraphs.Add(table);
doc.Save("c:/pdftest/TableInPDF.pdf");

Sorry, should have updated my post. My code sample was for delivering a Top and Bottom border while leaving the Right and Left without a border. That was my ultimate goal.

Really wish you guys would have followed an object model closer to .NET's model for tables. Took way too long to figure out how to do simple things.

Hi Robbe,

Thanks for you feedback. It is good to know you have managed to get your desired results.

rmorris-1:

Really wish you guys would have followed an object model closer to .NET's model for tables. Took way too long to figure out how to do simple things.


Although we have covered almost all the topics with code snippets in Programmer guide. Please feel free to share your concerns or the problem you faced in getting help form the documentation, It would help us to improve it.

Best Regards,

rmorris-1:
Sorry, should have updated my post. My code sample was for delivering a Top and Bottom border while leaving the Right and Left without a border. That was my ultimate goal.
Hi Robbe,

Sorry for the delayed response.

In order to set Top and Bottom border, please try using the following code line.

cell2.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Top|Aspose.Pdf.BorderSide.Bottom, 0.5F, Aspose.Pdf.Color.Red);

rmorris-1:
Really wish you guys would have followed an object model closer to .NET’s model for tables. Took way too long to figure out how to do simple things.
Aspose.Pdf for .NET has its own Document Object Model and the PDF generation and manipulation is performed according to DOM. Furthermore, we are continuously working on adding more and more documentation topics so that our customers get extensive details about features and their implementation. In the event of any further query, please feel free to contact.