title: iTextSharp Form Field Not Displaying ampersands, &, with SetField
body: <p>I'm having an issue with iTextSharp and a PDF form (form fields specifically) that I've spend nearly two days on that I am direly hoping someone has the answer to.</p>
  
  <p>I have a PDF form that when I open it as a user I can enter ampersands, &amp;, into form fields just fine.  However, when I use iTextSharp to fill in a form field value using .SetField the ampersands disappear.  I have tried using &amp; (which actually causes all the text in the field to appear as blank), the unicode representation of &amp;, not flattening the form, flattening the form, etc. all to no avail.  I am not sure what the issue could be as I mentioned the form field can certainly accept commas and ampersands with it's default encoding.  </p>
  
  <p>Is there something i'm missing?</p>
  
  <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      'Using iText 4.1.2.0
      GeneratePDF2()
  End Sub
  
  Private Sub GeneratePDF2()
      ''//The directory to output files to
      Dim WorkingFolder = My.Computer.FileSystem.SpecialDirectories.Desktop
  
      Dim FormFileName = Path.Combine(WorkingFolder, "testfile.pdf")
      Dim FinalFileName = Path.Combine(WorkingFolder, "Final.pdf")
  
      ''//The name of the form field that we are going to create
      Dim TextFieldName = "form1[0].#subform[0].Table3[0].Row2[0].Line2_FullName_and_AddressofEmployer[0]"
  
      Dim FieldValue As String = "Jonathan &amp; Chris &amp; Mark" ' Does Not Work
      'Dim FieldValue As String = "Jonathan and Chris and Mark" ' Works
  
      Dim Letter As RandomAccessFileOrArray
      'Create a PDF reader object based on the PDF template
      Dim PDFReader As PdfReader
      'Dim BAOS1 As MemoryStream
      Dim Stamper As PdfStamper
  
  
      Dim BAOS As MemoryStream = New MemoryStream()
      Dim Copy As PdfCopyFields = New PdfCopyFields(BAOS)
  
      Dim FormFilePath As String = FormFileName
      Letter = New RandomAccessFileOrArray(FormFilePath)
      'Create a PDF reader object based on the PDF template
      PDFReader = New PdfReader(Letter, Nothing)
  
      Dim BAOS1 As MemoryStream = New MemoryStream()
      Stamper = New PdfStamper(PDFReader, BAOS1)
  
      Dim FormFields As AcroFields = Stamper.AcroFields
  
      'Set field value
      FormFields.SetField(TextFieldName, FieldValue)
  
      'Rename field after setting value
      Dim RenamedFormFieldName As String
      RenamedFormFieldName = String.Concat(Guid.NewGuid().ToString, "_", Guid.NewGuid().ToString)
  
      FormFields.RenameField(TextFieldName, RenamedFormFieldName)
  
      ' flatten the form to remove editting options, set it to false
      ' to leave the form open to subsequent manual edits
      Stamper.FormFlattening = True
      ' close the pdf
      Stamper.Close()
  
      'This could be the correct location
      Copy.AddDocument(New PdfReader(BAOS1.ToArray))
  
      Copy.Writer.CloseStream = False
      Copy.Close()
  
      PDFReader = New PdfReader(BAOS.ToArray())
      Stamper = New PdfStamper(PDFReader, New FileStream(FinalFileName, FileMode.Create))
  
  
      Stamper.FormFlattening = True
      Stamper.Close()
  
  End Sub
  </code></pre>