Vb.net 在文本字段上添加签名-itextsharp
它不会抛出任何错误,但它只是不会把图像的pdf格式。 有人能找出我在这里遗漏了什么吗Vb.net 在文本字段上添加签名-itextsharp,vb.net,pdf,uitextfield,itext,Vb.net,Pdf,Uitextfield,Itext,它不会抛出任何错误,但它只是不会把图像的pdf格式。 有人能找出我在这里遗漏了什么吗 _pdfDocument = System.IO.Path.GetTempPath() & "TICKET_INFO.pdf" _pdfDocumentOutput = System.IO.Path.GetTempPath() & "TICKET_INFO_OUTPUT.pdf" SaveFromResources(_pdfDocument, My.Resources.template) Us
_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
字段DateMake显示在输出文件上,但图像不显示
编辑:无法将标签从移动应用更改为itextsharp
根据:
“官方”方法是使用按钮字段作为图像的占位符,并替换按钮的“图标”,如下所示:
编辑:字段类型为button,名称为button2
行更改为:
pdfForm.ReplacePushbuttonField("Button2", imageField.Field)
仍然没有显示图像。上面显示的代码狙击手解决了我的问题 请记住,在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
“描述”最初是什么类型的字段?文本还是按钮?@Mkl其文本字段您不能使用标记iTextSharp,因为该标记在几年前被删除,当时我们将iTextSharp的名称更改为.NET的iText。请不要再说了;改用.NET的iText。如果您的DLL引用了iTextSharp,则您可能正在使用旧版本的iText。当前版本是iText 7:您可能正在使用iText 5,但我们现在只发布iText 5的维护版本。iText 5正在逐步淘汰。您不应该再使用它。这是指向.NET的iText 7跳转入门教程的链接:(注意:如果您的字段是文本字段,“替换按钮字段”是没有意义的。文本字段不是按钮!这应该很简单,所以我不得不解释这一点,感觉有点尴尬,但显然您不知道。