【问题标题】:iTextSharp Inserting images GetFieldPositioniTextSharp 插入图像 GetFieldPosition
【发布时间】:2014-10-02 18:04:22
【问题描述】:

我正在使用 VB.NET 和 iTextSharp 库尝试将我在 PDF 中的图像放在现有字段上。

我正在尝试获取现场位置,以便绝对可以将图像放在那里,但它在我身上失败了,我不知道为什么。

我的代码是:

        Dim sig1file As String = HttpContext.Current.Server.MapPath("../files/userfiles/forms/" & tcode & "/" & tcode & "_pap_signature1.png")
        Dim sig1img As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(sig1file)

        Dim sig1positon() As Single = PDFFields.GetFieldPositions("payer1_signature1")
        Dim sig1rect As New Rectangle(sig1positon(1), sig1positon(2), sig1positon(3), sig1positon(4))
        sig1img.ScaleToFit(sig1rect.Width, sig1rect.Height)

        sig1img.SetAbsolutePosition(sig1positon(1) + (sig1rect.Width() - sig1img.ScaledWidth()) / 2, sig1positon(2) + (sig1rect.Height() - sig1img.ScaledHeight()) / 2)
        Dim imagewriter As iTextSharp.text.pdf.PdfContentByte = PDFStamper.GetUnderContent(1)
        imagewriter.AddImage(sig1img)

我收到以下错误:

App_Web_y4xg45gn.dll 中出现“System.InvalidCastException”类型的异常,但未在用户代码中处理

附加信息:无法将“System.Collections.Generic.List`1[iTextSharp.text.pdf.AcroFields+FieldPosition]”类型的对象转换为“System.Single[]”类型。

谁能帮忙?

谢谢

【问题讨论】:

    标签: vb.net pdf itextsharp


    【解决方案1】:

    我实际上解决了我自己的问题。

    解决办法是这样的

            Dim sig1file As String = HttpContext.Current.Server.MapPath("../files/userfiles/forms/" & tcode & "/" & tcode & "_pap_signature1.png")
            Dim sig1img As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(sig1file)
    
            Dim sig1position As System.Collections.Generic.IList(Of AcroFields.FieldPosition) = PDFFields.GetFieldPositions("payer1_signature1")
            Dim test As AcroFields.FieldPosition = sig1position(0)
            Dim left, right, top, bottom As Single
            left = test.position.Left
            right = test.position.Right
            top = test.position.Top
            bottom = test.position.Bottom
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-01
      • 1970-01-01
      • 2016-03-03
      • 2010-10-09
      • 1970-01-01
      • 1970-01-01
      • 2013-11-11
      相关资源
      最近更新 更多