c# – itextsharp pdfpcell垂直对齐问题
发布时间:2020-12-15 21:15:12 所属栏目:百科 来源:网络整理
导读:我如何将两个单元格垂直对齐在一起.目前,第二个单元格呈现在第一个单元格下方.第一个单元格是图像,第二个单元格是文本.这是我的代码. private Document pdoc; Font font99 = FontFactory.GetFont("HELVETICA",60); PdfPTable pdfRatingTable = new PdfPTable
我如何将两个单元格垂直对齐在一起.目前,第二个单元格呈现在第一个单元格下方.第一个单元格是图像,第二个单元格是文本.这是我的代码.
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); 解决方法
看起来您的图像比表格中单元格的最大宽度宽(加上相当大的填充),因此下一个单元格出现在下一行中.
我建议尝试使用更小的图像(或更小的相同图像)来查看我是否正确. 或者“在下面”你的意思是它们都在同一行,但文本出现在单元格的底部,而图像在中间,周围有一个20点的垫,所以文本完全在图像下方? IIRC,段落将占用整个单元格,但是块将遵循单元格垂直和水平对齐设置.请参阅my answer here中的评论. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |