问题描述
我正在尝试使用itextsharp创建Pdf。我添加了一个包含两列的表,其中一列包含文本和其他图像。我想要有恒定的图像大小
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
-
如果另一个单元格中的文本增加并且图像存在于其他单元格中,我的图像会自动调整大小具有不同的大小
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);
}
2.然后我更改了代码,但现在图像大小增加并占据整个单元格
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);
}
推荐答案
我认为你是这样自己缩放图像的: noicon.ScaleAbsolute(35f,35f);
I think you're scaling the image yourself like this: noicon.ScaleAbsolute(35f, 35f);
这也困惑了我为什么要将图像包装在里面a 块
。您可以创建一个 PdfPCell
,它将 Image
作为参数以及 Bool
定义iText是否应缩放 Image
。请参阅本书(我是其作者)一书的第109页,并查看XMen 的示例。
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.
这篇关于插入PdfCell时,图像会调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!