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 6335769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:55:16+00:00 2026-05-24T18:55:16+00:00

I am creating table and adding cells to table with text or image content.

  • 0

I am creating table and adding cells to table with text or image content.

var  pdfTable = new PdfPTable(2);
                nCell = new PdfPCell(new Phrase("A")) {HorizontalAlignment = 1};
                pdfTable.AddCell(nCell);
                pdfTable.AddCell("B");
                pdfTable.AddCell(qrImg);
                pdfTable.AddCell(image39);
                pdfTable.AddCell("C");
                pdfTable.AddCell("D");
                pdfTable.SpacingBefore = 20f;
                pdfTable.SpacingAfter = 30f;
                document.Add(pdfTable);

renders 3 rows and displays image in row2

if I add cells by creating pdfpcell object first:

 var cell = new PdfPCell(qrImg};
 pdfTable.AddCell(nCell);

only rows 1 and 3 are visible.

If I add height property to cell then the image gets diaplayed.

my questions ( 3 but related);
is it required for us to specify height when adding cell with image ( cells added with text content – phrase resenders correctly) ?
Is there something I am missing when creating a new cell, which prevents images to be rendered?
should I always be using Addcell(image) when adding image content?

Thank you all,
Mar

  • 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-24T18:55:17+00:00Added an answer on May 24, 2026 at 6:55 pm

    Its easier to understand what’s going on if you browse the source. A table within iText keeps a property around called DefaultCell that gets reused over and over. This is done so that the basic cell properties are kept from cell to cell. When you call AddCell(Image) the DefaultCell‘s image is set to the image, then added to the table, and finally the image get’s null’d out.

    543     defaultCell.Image = image;
    544     AddCell(defaultCell);
    545     defaultCell.Image = null;
    

    The PdfCell(Image) constructor actually internally calls an overload PdfPCell(Image, bool) and passes false as the second parameter, fit. Here’s the constructor’s conditional on fit:

    152     if (fit) {
    153         this.image = image;
    154         Padding = borderWidth / 2;
    155     }
    156     else {
    157         column.AddText(this.phrase = new Phrase(new Chunk(image, 0, 0, true)));
    158         Padding = 0;
    159     }
    

    If you pass false to fit, which is the default, you’ll see that the image is added in a much more complicated way.

    So basically you can add an image in three main ways (okay, lots more actually if you use nested tables or chunks or phrases), the first below picks up the defaults and is probably what you want. The second is more raw but gets you closer to what you probably want. The third is the most raw and assumes that you know what you’re doing.

    var qrImg = iTextSharp.text.Image.GetInstance(sampleImage1);
    
    //Use the DefaultCell, including any existing borders and padding
    pdfTable.AddCell(qrImg);
    
    //Brand new cell, includes some padding to get the image to fit
    pdfTable.AddCell(new PdfPCell(qrImg, true));
    
    //Brand new cell, image added as a Chunk within a Phrase
    pdfTable.AddCell(new PdfPCell(qrImg));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just creating a new table using MySQL Query Browser, and noticed there's
i am creating a table layout with radio group by dynamically adding radiobuttons to
After creating a table (by migration), I want to insert some entries directly. How
I'm creating a table that looks something like this. CREATE TABLE packages ( productCode
I am dynamically creating a table which I want to have clickable rows. When
I am creating a table for an application that handles scheduling and deals with
I'm creating a table in an asp.net code behind dynamically, and I want to
I'm creating a table with: CREATE TABLE movies ( id INT AUTO_INCREMENT PRIMARY KEY,
What would be the code for creating a table with two foreign keys? I
It is my understanding that the default behavior when creating a table in SQL

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.