在文本字段上添加签名 - itextsharp
Add signature on text field - itextsharp
它不会抛出任何错误,但不会将图像放入 pdf 格式。
谁能知道我在这里遗漏了什么
_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
字段 DateMade 显示在输出文件中,但图像未显示。
编辑:无法从移动应用程序将标签更改为 itextsharp
根据 : Whosebug - itext
执行此操作的 "official" 方法是使用按钮字段作为图像的占位符,并像这样替换按钮的 "icon":
编辑:字段类型为 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
它不会抛出任何错误,但不会将图像放入 pdf 格式。 谁能知道我在这里遗漏了什么
_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
字段 DateMade 显示在输出文件中,但图像未显示。
编辑:无法从移动应用程序将标签更改为 itextsharp
根据 : Whosebug - itext
执行此操作的 "official" 方法是使用按钮字段作为图像的占位符,并像这样替换按钮的 "icon":
编辑:字段类型为 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