0

Following an example I found on SO (how to set width for pdfpcell) for extrapolating adding a cell to a PdfPTable into a method I have created one that sets all my parameters except the Rectangle values for cell.Border. How do I fix my method so I can pass in any Rectangle values I need?

Rectangle is and object derived from Element, IElement in ITextSharp.

Potential Rectangle values are:

Rectangle.LEFT_BORDER, Rectangle.TOP_BORDER, Rectangle.RIGHT_BORDER, Rectangle.BOTTOM_BORDER, Rectangle.NO_BORDER

or can be accessed by their numerical values:

BOTTOM_BORDER = 2, LEFT_BORDER = 4, NO_BORDER = 0, RIGHT_BORDER = 8, TOP_BORDER = 1

Example: cell.Border = 1 | 2 | 8; or cell.Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER;

What's hanging me up is the '|' that has to be between the values and cell.Border will not accept a string;

Here is the method:

 private static void addCell(PdfPTable table, string phrase, int colspan, int height, Font font)
 {
    PdfPCell cell = new PdfPCell(new Phrase(phrase, font));
    cell.Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER;  ** need to set param here ** 
    cell.BorderWidth = 1;
    cell.Colspan = colspan;
    cell.FixedHeight = height;
    table.AddCell(cell);
 }
Community
  • 1
  • 1
Elaine K
  • 507
  • 2
  • 7
  • 32
  • *What's hanging me up is the '|' that has to be between the values and cell.Border will not accept a string;* - why should the *or* operator accept strings? Why would you expect it to do so? – mkl Nov 27 '14 at 08:48

1 Answers1

0

The answer to my question was to pass in the appropriate values as an int into the method. The rectangle values have numerical values and the call sums them into one number that is passed into the method. There is a specific term for this but it escapes me at the moment.

addCell(tableName, "MyPhrase", 1, 1, MyFont, Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;

private static void addCell(PdfPTable table, string phrase, int colspan, int height, Font font, int border)
{
   PdfPCell cell = new PdfPCell(new Phrase(phrase, font));
   cell.Border =  border;
   cell.BorderWidth = 1;
   cell.Colspan = colspan;
   cell.FixedHeight = height;
   table.AddCell(cell);
}
Elaine K
  • 507
  • 2
  • 7
  • 32