【问题标题】:How to center image on table cell pdf file in iTextSharp如何在 iTextSharp 中的表格单元格 pdf 文件上居中图像
【发布时间】:2018-03-26 21:24:27
【问题描述】:

我无法使用 iTextSharp 将图像集中在表格单元格上。

我试过这种模式,没有成功。

图像始终相对于单元格未对齐,并覆盖 pdf 文件中的上部单元格。

如何解决这个问题?

下面是我的代码。

string imagePath = "~/aspnet/Img/pdf.gif";
iTextSharp.text.Image image2 = iTextSharp.text.Image.GetInstance(imagePath);
image2.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
Chunk cImage = new Chunk(image2, 0, 0, false);
Anchor anchor = new Anchor(cImage);
anchor.Reference = "www.mywebsite.com";
table.AddCell(anchor);

【问题讨论】:

    标签: itext


    【解决方案1】:

    请试试这个。

    您必须使用属性Annotation of iTextSharp

    string imagePath = "~/aspnet/Img/pdf.gif";
    iTextSharp.text.Image image2 = iTextSharp.text.Image.GetInstance(imagePath);
    PdfPCell cell2 = new PdfPCell(image2);
    cell2.HorizontalAlignment = Element.ALIGN_LEFT;
    cell2.VerticalAlignment = Element.ALIGN_MIDDLE;
    cell2.FixedHeight = 20;
    image2.Annotation = new Annotation(0, 0, 0, 0, "www.mywebsite.com");
    table.AddCell(cell2);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-13
      • 2014-02-10
      • 2011-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多