I'm using visual basic in conjunction with iTextSharp to populate a PDF form.
All is wonderful except from the fact that the length of one of the form fields is too short.
From what I can determine, I need to remove the MAXLEN value for the field from the dictionary...but I'm jiggered if I can find out how to do this using VB and iTextSharp.
The field itself is called "internalP" and is currently set to a length of 4 characters. I need it set to 10 characters.
I did assume that I could edit the field somehow, but having spent several hours looking around, I think the solution is just to remove the MAXLEN property, it's just that I cannot find any example code.
Can anybody help please?
The code I am running so far is this:
Hi, my code is as follows:
Imports iTextSharp.text.pdf
Imports iTextSharp.text
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim pdfTemplate As String = "z:\shared\LP1F.pdf"
Dim newFile As String = "z:\shared\Final.pdf"
Dim pdfReader As New PdfReader(pdfTemplate)
Dim pdfStamper As New PdfStamper(pdfReader, New FileStream(newFile, FileMode.Create))
Dim pdfFormFields As AcroFields = pdfStamper.AcroFields
' set form pdfFormFields
'''
'this was my first attempt but is not working
'I receive a compilation error saying that I can't use nul'
'''
pdfFormFields.SetFieldProperty("internalP", "FieldMaxLength", 10, null)
pdfFormFields.RegenerateField("internalP")
pdfFormFields.SetField("internalP", "1234567890")
'''
' therefore I started with this code, but then got stuck!!
'''
Dim item As AcroFields.Item
item = pdfFormFields.GetFieldItem("internalP")
Dim pdfDictionary As PdfDictionary = item.GetWidget(0)
pdfDictionary.Remove(PdfName.MAXLEN)
MessageBox.Show("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
End Class