2

I'm trying to create Pdf using itextsharp. I have added one table conataining two columns one containing text and other image. I want to have constant image size

  1. My Image automatically resizes if the text present in another cell increases and image present in other cell has different sizes

      for (int i = 0; i < visitInfo.VisitsiteComplience.Count; ++i)
        {
    
            cellprop.Colspan = 1;
            cellprop.Pharse = visitInfo.VisitsiteComplience[i].Compliencedescription;
            cellprop.BaseColor = null;
            table.AddCell(AddCelltoTable(cellprop));
            yesicon.ScaleAbsolute(35f, 35f);
            noicon.ScaleAbsolute(35f, 35f);
    
            if (visitInfo.VisitsiteComplience[i].Status == "1")
            {
    
                statuscell.AddElement(new Chunk(noicon, 0, 0));
    
            }
            else
            {
    
               // statuscell.AddElement(new Chunk(noicon, 0, 0));
            }
    
    
           statuscell.FixedHeight = 10;
    
    
            //headerLeftCell.Border = PdfPCell.NO_BORDER;
            table.AddCell(statuscell);
        }
    

enter image description here 2. Then I changed the code but now Image size increases and occupies full cell

     for (int i = 0; i < visitInfo.VisitsiteComplience.Count; ++i)
        {

            cellprop.Colspan = 1;
            cellprop.Pharse = visitInfo.VisitsiteComplience[i].Compliencedescription;
            cellprop.BaseColor = null;
            table.AddCell(AddCelltoTable(cellprop));
            yesicon.ScaleAbsolute(35f, 35f);
            noicon.ScaleAbsolute(35f, 35f);

            if (visitInfo.VisitsiteComplience[i].Status == "1")
            {

                statuscell.AddElement(new Chunk(noicon, 0, 0));

            }
            else
            {

               // statuscell.AddElement(new Chunk(noicon, 0, 0));
            }





            //headerLeftCell.Border = PdfPCell.NO_BORDER;
            table.AddCell(statuscell);
        }

enter image description here

user641812
  • 335
  • 5
  • 19

2 Answers2

3

I think you're scaling the image yourself like this: noicon.ScaleAbsolute(35f, 35f);

It also puzzles me why you're wrapping the image inside a Chunk. You can create a PdfPCell that takes an Image as parameter as well as a Bool to defines whether or not iText should scale the Image. See page 109 of the book iText in Action (of which I'm the author) and take a look at the XMen example of chapter 4.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
0
Image image = Image.getInstance("D:/star.png");

PdfPCell cell = new PdfPCell();

cell.setFixedHeight(40f);

cell.addElement(image);

table.addCell(cell);
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109