我以下列方式使用PdfPTable
var myTable = new PdfPTable( 3 );
foreach(var nextString in myStrings)
{
var nextCell = new PdfPCell( new Phrase( nextString, smallFont ) );
nextCell.Border = Rectangle.NO_BORDER;
nextCell.AddCell(nextCell);
}
pdfDocument.Add(myTable);
Run Code Online (Sandbox Code Playgroud)
一切都很完美,然后总细胞数乘以列数(3).但是当我想创建一个包含3列但只有4个单元格的表时 - 最后一行是不可见的.
怎么解决这个问题?
itextsharp 5.3.3.0
我试图PdfPCell在一个循环中添加一个Table带有2列的iTextSharp Document.但是如果循环内的计数是奇数.然后最后一个单元格没有被添加.有人可以提供这个问题的解决方案吗?我的代码如下:
var doc = new Document();
PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("~/QrCodes/") + fileName + ".pdf", FileMode.Create));
doc.Open();
PdfPTable table = new PdfPTable(2);
table.WidthPercentage = 100;
foreach (var item in items)
{
if (itemImages.Any(p => p.Reference == item.Reference) == true)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(@item.ItemQrCode));
iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(image, ImageFormat.Jpeg);
PdfPCell cellImage = new PdfPCell(pdfImage);
cellImage.HorizontalAlignment = Element.ALIGN_CENTER;
cellImage.VerticalAlignment = Element.ALIGN_MIDDLE;
cellImage.Border = 0;
table.AddCell(cellImage);
}
}
doc.Add(table);
doc.Close();
Run Code Online (Sandbox Code Playgroud)