【问题标题】:Image resizes when inserted in PdfCell图像在插入 PdfCell 时调整大小
【发布时间】:2013-04-01 10:46:05
【问题描述】:

我正在尝试使用 itextsharp 创建 Pdf。我添加了一个包含两列的表,其中一列包含文本和其他图像。我想要恒定的图像大小

  1. 如果另一个单元格中的文本增加并且其他单元格中的图像大小不同,我的图像会自动调整大小

      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);
        }
    

2.然后我更改了代码,但现在图像大小增加并占据了整个单元格

     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);
        }

【问题讨论】:

    标签: image itextsharp


    【解决方案1】:

    我认为您正在像这样自己缩放图像:noicon.ScaleAbsolute(35f, 35f);

    这也让我感到困惑,为什么您将图像包装在 Chunk 中。您可以创建一个PdfPCell,它以Image 作为参数以及Bool 来定义iText 是否应该缩放Image。请参阅本书iText in Action(我是作者)的第109页,并查看chapter 4的XMen示例。

    【讨论】:

      【解决方案2】:
      Image image = Image.getInstance("D:/star.png");
      
      PdfPCell cell = new PdfPCell();
      
      cell.setFixedHeight(40f);
      
      cell.addElement(image);
      
      table.addCell(cell);
      

      【讨论】:

      • 最好添加描述代码的作用/如何解决问题,而不仅仅是代码
      猜你喜欢
      • 2015-07-23
      • 2010-12-21
      • 1970-01-01
      • 2023-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多