I need to style a ton of different elements (read: "cells") in a PDF using iTextSharp. Label, header, subheader, number, etc. Right now, I'm using three different methods for each cell type:
public static PdfPCell GetDefaultCell(string strText)
{
PdfPCell cell = new PdfPCell(new Phrase(strText, GetDefaultFont()));
cell.Border = 0;
return cell;
}
public static PdfPCell GetDefaultCell(string strText, int iColspan)
{
PdfPCell cell = new PdfPCell(new Phrase(strText, GetDefaultFont()));
cell.Border = 0;
cell.Colspan = iColspan;
return cell;
}
public static PdfPCell GetDefaultCell(string strText, int iColspan, int iAlign)
{
PdfPCell cell = new PdfPCell(new Phrase(strText, GetDefaultFont()));
cell.Border = 0;
cell.Colspan = iColspan;
cell.HorizontalAlignment = iAlign;
return cell;
}
Where "Default" is substituted with the cell type for each set of three methods. I don't think this scales. Especially if I end up with more than the 20 or 30 types I have now. What if I want to modify more than just the colspan and horizontalalignment attributes? Can I use delegates here? The only difference in my method calls is the name and the GetXFont() call within the method.