在Setfield之后无法关闭PDFStamper

时间:2013-06-21 16:03:48

标签: vb.net itextsharp

下面的VB.Net代码在v 5.3.4下工作,但.Close语句在v5.4.1和v5.4.1下失败。我可以使用相同的代码并切换.dll来重现问题。

第二行中的Me.Text是一个包含文件路径的文本框。该文件是使用AcroBat 9.5创建的,它有两个名为“NAME”和“PHONE”的表单字段。

core.zip中的itextsharp.dll被添加为项目的引用。在表单级别:IMPORTS itextsharp.text和.text.pdf。谢谢!

有人可以验证这一点并报告错误吗?或者让我知道我做错了什么(除了使用WinForms和VB.Net :)?

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    Dim newFile As String = Me.Text.Replace(".pdf", "_Out.pdf")

    ''//create w/overwrite copy of the template
    Dim pdfReader As New PdfReader(pdfTemplate)
    Dim pdfStamper As New PdfStamper(pdfReader, New FileStream(newFile, FileMode.Create))

    pdfFormFields = pdfStamper.AcroFields

    ''//set form pdfFormFields ' field names are case sensitive
    pdfFormFields.SetField("NAME", "Firstname Lastname")
    pdfFormFields.SetField("PHONE", "805.555.1212")

    ''//report by reading values from completed PDF
    Dim sTmp As String = "Completed: " + pdfFormFields.GetField("NAME") + " " + _
    pdfFormFields.GetField("PHONE")
    MessageBox.Show(sTmp, "Finished")

    ''//flatten the form to remove editting options, set it to false
    ''//to leave the form open to subsequent manual edits
    pdfStamper.FormFlattening = False

    ''//close the pdf
    pdfStamper.Close()
End Sub

0 个答案:

没有答案