加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 奇数编号单元格未添加到Pdf

发布时间:2020-12-16 00:09:05 所属栏目:asp.Net 来源:网络整理
导读:我试图将循环中的PdfPCell添加到文档中有2列的iTextSharp表中.但是如果循环内的计数是奇数.然后最后一个单元格没有被添加.有人可以提供这个问题的解决方案吗? 我的代码如下: var doc = new Document(); PdfWriter.GetInstance(doc,new FileStream(Server.M
我试图将循环中的PdfPCell添加到文档中有2列的iTextSharp表中.但是如果循环内的计数是奇数.然后最后一个单元格没有被添加.有人可以提供这个问题的解决方案吗?

我的代码如下:

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();

解决方法

在你的PdfPTable上,你可以在完成后调用 CompleteRow()方法,并填写缺少的单元格.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读