在文本字段上添加签名-itextsharp

时间:2018-06-27 21:14:40

标签: vb.net pdf uitextfield itext

它不会引发任何错误,但只会将图像放入pdf格式。 谁能弄清楚我在这里想念什么

for i in range (len(userCards)):
  print("i is "+str(userCards[i]))
  if userCards.count(userCards[i]) == 4:
    userMatches = userMatches + 1
    userCards.remove(userCards[i])

字段DateMade显示在输出文件上,但图像未显示。

编辑:无法将标签从移动应用更改为itextsharp

根据:Stackoverflow - itext

执行此操作的“官方”方法是将Button字段用作图像的占位符,并替换按钮的“ icon”,如下所示:

编辑:字段类型为button,名称为button2

enter image description here

行更改为:

_pdfDocument = System.IO.Path.GetTempPath() & "TICKET_INFO.pdf"
_pdfDocumentOutput = System.IO.Path.GetTempPath() & "TICKET_INFO_OUTPUT.pdf"
SaveFromResources(_pdfDocument, My.Resources.template)

Using reader As New PdfReader(_pdfDocument)
    Using stamper As New PdfStamper(reader, New IO.FileStream(_pdfDocumentOutput, IO.FileMode.Create))

        Dim pdfForm As AcroFields = stamper.AcroFields

        Dim test As System.Drawing.Image = Image.FromFile("123.jpg")
        Dim logo As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(test, System.Drawing.Imaging.ImageFormat.Png)

        Dim fieldPosition As AcroFields.FieldPosition = stamper.AcroFields.GetFieldPositions("Description")(0)
        Dim imageField As New PushbuttonField(stamper.Writer, fieldPosition.position, "Description")
        imageField.Image = logo

        pdfForm.SetField("DateMade", "123")

        pdfForm.ReplacePushbuttonField("Description", imageField.Field)

        stamper.FormFlattening = True

    End Using
End Using

仍然没有显示图像。

1 个答案:

答案 0 :(得分:0)

上面显示的代码窃听器解决了我的问题。

请记住,在pdf表单上,您需要添加字段类型按钮来完成此操作

Dim _pdfDocument = "template.pdf"
        Dim _pdfDocumentOutput = "template_out.pdf"

        Using reader As New PdfReader(_pdfDocument)
            Using stamper As New PdfStamper(reader, New IO.FileStream(_pdfDocumentOutput, IO.FileMode.Create))

                Dim pdfForm As AcroFields = stamper.AcroFields

                Dim Signature As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(Image.FromFile("123.jpeg"),
                                                                                      Imaging.ImageFormat.Png)

                Dim ad As PushbuttonField = stamper.AcroFields.GetNewPushbuttonFromField("Image-1")
                ad.Layout = PushbuttonField.LAYOUT_ICON_ONLY
                ad.ProportionalIcon = True
                ad.Image = Signature
                ad.BackgroundColor = iTextSharp.text.BaseColor.WHITE
                pdfForm.ReplacePushbuttonField("Image-1", ad.Field)
                pdfForm.SetField("Description-1", "DESC !")

                stamper.FormFlattening = True

            End Using
        End Using