C# itextsharp pdfpcell垂直对齐问题
如何使两个单元格垂直对齐。当前,第二个单元渲染在第一个单元下面。第一个单元格是图像,第二个单元格是文本。这是我的密码C# itextsharp pdfpcell垂直对齐问题,c#,itextsharp,C#,Itextsharp,如何使两个单元格垂直对齐。当前,第二个单元渲染在第一个单元下面。第一个单元格是图像,第二个单元格是文本。这是我的密码 private Document pdoc; Font font99 = FontFactory.GetFont("HELVETICA", 60); PdfPTable pdfRatingTable = new PdfPTable(2); PdfPCell pRatCell = null; pdfRatingTable.WidthPerce
private Document pdoc;
Font font99 = FontFactory.GetFont("HELVETICA", 60);
PdfPTable pdfRatingTable = new PdfPTable(2);
PdfPCell pRatCell = null;
pdfRatingTable.WidthPercentage = 100;
pdfRatingTable.SetWidths(new int[] { 75, 25 });
hImage = iTextSharp.text.Image.GetInstance(MapPath("~/Images/fyler3_Rating.jpg"));
NewWidth = 338;
MaxHeight = 18;
if (hImage.Width <= NewWidth)
{
NewWidth = hImage.Width;
}
NewHeight = hImage.Height * NewWidth / hImage.Width;
if (NewHeight > MaxHeight)
{
NewWidth = hImage.Width * MaxHeight / hImage.Height;
NewHeight = MaxHeight;
}
ratio = hImage.Width / hImage.Height;
hImage.ScaleAbsolute(NewWidth, NewHeight);
pRatCell = new PdfPCell(hImage);
pRatCell.Border = 0;
pRatCell.PaddingLeft = 20f;
pRatCell.HorizontalAlignment = Element.ALIGN_LEFT;
pdfRatingTable.AddCell(pRatCell);
pRatCell = new PdfPCell(new Phrase(new Chunk("405", font99)));
pRatCell.HorizontalAlignment = Element.ALIGN_LEFT;
pRatCell.Border = 0;
pRatCell2.VerticalAlignment = Element.ALIGN_TOP;
pdfRatingTable.AddCell(pRatCell);
pdoc.Add(pdfRatingTable);
私有文档pdoc;
Font font99=FontFactory.GetFont(“HELVETICA”,60);
PdfPTable pdfRatingTable=新的PdfPTable(2);
PdfPCell-pRatCell=null;
pdfRatingTable.WidthPercentage=100;
SetWidths(新的int[]{75,25});
hImage=iTextSharp.text.Image.GetInstance(MapPath(“~/Images/fyler3_Rating.jpg”);
新宽度=338;
最大高度=18;
if(hImage.Width最大高度)
{
NewWidth=hImage.Width*MaxHeight/hImage.Height;
NewHeight=MaxHeight;
}
比率=hImage.宽度/hImage.高度;
hImage.可缩放溶质(新宽度、新高度);
pRatCell=新的PdfPCell(hImage);
pRatCell.Border=0;
pRatCell.PaddingLeft=20f;
pRatCell.HorizontalAlignment=Element.ALIGN_LEFT;
pdfRatingTable.AddCell(pRatCell);
pRatCell=新的PdfPCell(新短语(新语块(“405”,font99));
pRatCell.HorizontalAlignment=Element.ALIGN_LEFT;
pRatCell.Border=0;
pRatCell2.VerticalAlignment=元素.ALIGN\u TOP;
pdfRatingTable.AddCell(pRatCell);
pdoc.Add(pdfRatingTable);
看起来您的图像比表中某个单元格的最大宽度宽(加上相当大的填充),因此下一个单元格显示在下一行中
我建议用一张小得多的图片(或者是同一张小比例的图片)试试看我是否正确
或“下”是指它们都在同一行中,但是文本出现在单元格的底部,而图像位于中间,周围有20个点,因此文本完全在图像下面?
IIRC,
段落
将占据整个单元格,但区块
将遵循单元格的垂直和水平对齐设置。请参见中的注释。Hi Mark,我甚至将图像的大小调整为稍小一点,但右边的单元格仍显示在下一行中。甚至我也用pRatCell=newpdfpcell(新短语(newchunk)(“这是一个测试”))替换了这个图像;第二个单元格仍显示在下一行中。我为表格设置的宽度看起来合适吗?我建议你打开单元格边框,以确保它确实位于下一行,而不是更低(我希望使用20磅的垫子)。谢谢设置边框帮助解决了这个问题。我需要在第一个单元格的顶部添加一些填充物,以便将其与下一个单元格对齐。再次感谢。