AndreaNobili AndreaNobili - 1 month ago 5
ASP.NET (C#) Question

How to show both the bottom and the top border of a cell in iTextSharp?

I am very new in iTextSharp (the iText porting for C#) and I am going crazy with the followint situation.

In the application that I am working on I have a table definied in this way:

table = new PdfPTable(2);
table.SetWidths(new int[] { 100, 500 });
//table.WidthPercentage = 95;

table.AddCell(new PdfPCell(new Phrase("Description:")) { Border = PdfPCell.BOTTOM_BORDER, Padding = 5, MinimumHeight = 50, PaddingTop = 15 });

table.AddCell(new PdfPCell(new Phrase(currentVuln.ShortSummary)) { Border = PdfPCell.BOTTOM_BORDER, Padding = 5, MinimumHeight = 50, PaddingTop = 15 });
_document.Add(table);


s you can see a new cell is add to the table creating it passing to it the string that have to show in itself and after passing some grphical settings.

For example:

table.AddCell(new PdfPCell(new Phrase("Description:")) { Border = PdfPCell.BOTTOM_BORDER, Padding = 5, MinimumHeight = 50, PaddingTop = 15 });


it add a new cell that show the string Description and the graphical settings into the {...} block are applied.

My first doubt is: what exactly is this syntax? is it a C# syntax or it is something related to iTextSharp?

Thene I am going crazy to understand what exactly happen when this settings are applied in particular when it is evaluate this section: Border = PdfPCell.BOTTOM_BORDER

1) Border is an int value into the iTextSharp.text.Rectangle class that take the value of PdfPCell.BOTTOM_BORDER returned value

2) PdfCell is another class that is into the iTextSharp.text.pdf namespace and it don't contains the BOTTOM_BORDER property but this class is definied in this way:

public class PdfPCell : Rectangle, IAccessibleElement


So the PdfCell class is itself a Rectangle and the BOTTOM_BORDER property is into Rectangle class, infact here I have

public const int BOTTOM_BORDER = 2;


Ok...so I think that doing:

Border = PdfPCell.BOTTOM_BORDER is the same thing that do: Border = 2 that sets a specific type of border to my cell. Is it right?

The doubt is: why I have to pass to the PdfPCell class (that is a Rectangle) to set the border and I don't set it directly on Rectangle?

I have also the following problem: by Border = PdfPCell.BOTTOM_BORDER I show only the bottom border of a cell, what can I do to show the bottom and the upper bord of a cell?

Tnx

Answer

More than likely it is flag based.

Give this a shot:

Border = PdfPCell.BOTTOM_BORDER | PdfPCell.TOP_BORDER
Comments