我确实有问题,我有一个有短语的细胞, 我想在短语的左边有一个小图标, 但是每个元素都是在一条新线上
这是我的代码 返回单元格:
var cell = new PdfPCell();
Bitmap bitmap = new Bitmap(21, 21);
Graphics g = Graphics.FromImage(bitmap);
g.Clear(Color.White);
SolidBrush brush = new SolidBrush(colour);
g.FillEllipse(brush, 0, 0, 20, 20);
brush.Dispose();
g.DrawImageUnscaled(bitmap, 0, 0);
g.Dispose();
var imgIcon = iTextSharp.text.Image.GetInstance(bitmap, System.Drawing.Imaging.ImageFormat.Jpeg);
bitmap.Dispose();
//imgIcon.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_RIGHT;
cell.AddElement(imgIcon);
var phrase = new Phrase(o.ToString(), Report.Fonts.Table);
cell.AddElement(phrase);
//this code scales the image so that it does not fit the cell
foreach (IElement element in cell.CompositeElements)
{
PdfPTable tblImg = element as PdfPTable;
if (tblImg != null)
{
tblImg.TotalWidth = 10;
tblImg.LockedWidth = true;
}
}
return cell;
这是输出 :
""https://i.sstatic.net/U6Kn.png" alt="此处的内置图像描述"/ >
如有任何帮助,将不胜感激。
--edit: here is the output with imgIcon s alignment property set
""https://i.sstatic.net/5qUjY.png" alt="此处输入图像描述"/ >