Resize image when pasting into PdfCell

I am trying to create Pdf using itextsharp. I added one table containing two columns containing text and another image. I want to have a constant image size

  • My image is automatically resized if the text present in another cell is enlarged and the image present in another cell is 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 the size of the image increases and takes up a 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

+2


source to share


2 answers


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



It also puzzles me why you are wrapping the image inside Chunk

. You can create PdfPCell

one that takes an Image

as parameter and also Bool

to determine if iText should scale Image

. See p. 109 of the iText book in action (of which I am the author) and take a look at the XMen example chapter 4 .

+3


source


Image image = Image.getInstance("D:/star.png");

PdfPCell cell = new PdfPCell();

cell.setFixedHeight(40f);

cell.addElement(image);

table.addCell(cell);

      



0


source







All Articles