Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 719737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:40:41+00:00 2026-05-14T05:40:41+00:00

I need to style a ton of different elements (read: cells) in a PDF

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:40:42+00:00Added an answer on May 14, 2026 at 5:40 am

    You can pass a delegate to the method which returns the font:

    public static PdfPCell GetCell(string strText, Func<Font> fontCreator)
    {
        PdfPCell cell = new PdfPCell(new Phrase(strText, fontCreator()));
        cell.Border = 0;
        return cell;
    }
    
    var cell = GetCell("...", () => GetDefaultFont());
    

    But why don’t you simply pass the font directly to the method?

    public static PdfPCell GetCell(string strText, Font font)
    {
        PdfPCell cell = new PdfPCell(new Phrase(strText, font));
        cell.Border = 0;
        return cell;
    }
    
    var cell = GetCell("...", GetDefaultFont());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a tr:table that I need to style using CSS. All the normal
I need to style two different inputs to appear differently on mouseover and on
I need to style a regular html list like the following picture: as you
I need to style the browse button of file upload in GWT.... I found
I've got an HTML select box that I need to style. I'd prefer to
How to change color of selected ListPicker Item in Full Mode? What style need
I need to apply a style on a recurring element which has a fixed
I need to add some accordian style expand/collapse handles to a series of parent
I need to implement an android broadcast style IPC - not dissimilar in concept
I need to change the spinner's style because if i place the spinner in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.