I have a pdf form with 4 fields to be populated with data. This file is saved into a memory stream and appended to a larger pdf document. It is deployed into IIS7 environment using .NET 4.0. This works in my development environment. The problem is that the form field data disappears when I deploy it to the server.
My code that works in development environments is at follows:
If IO.File.Exists(templateFile) Then
Dim appendDocStream As IO.Stream = New IO.MemoryStream
Dim appendDoc As PdfLoadedDocument = New PdfLoadedDocument(templateFile)
Try
' Load the form from the loaded document.
Dim form As PdfLoadedForm = appendDoc.Form
' Load the form field collections from the form.
Dim field As New PdfLoadedFormFieldCollection(form)
Dim thisField As PdfLoadedField = Nothing
Dim fieldValue As String = String.Empty
' TryGetField Method.
If field.TryGetField("Date", thisField) Then
TryCast(thisField, PdfLoadedTextBoxField).Text = "20 Sep 2013"
End If
If field.TryGetField("Client", thisField) Then
TryCast(thisField, PdfLoadedTextBoxField).Text = "Test Name"
End If
If field.TryGetField("Project", thisField) Then
TryCast(thisField, PdfLoadedTextBoxField).Text = "Test AddressText"
End If
If field.TryGetField("DrawingNo", thisField) Then
TryCast(thisField, PdfLoadedTextBoxField).Text = "TestDrawing 001"
End If
'form.Flatten = True ' ' NOTE this line deletes the populated field data
appendDoc.Save(appendDocStream)
appendDoc.Dispose()
appendDoc = New PdfLoadedDocument(appendDocStream)
Catch ex As Exception
ErrorHandler.LogMsg(templateFile & " is not a pdf form")
End Try
pdfDoc.Append(appendDoc)
appendDoc.Dispose()
End If
Does anyone have any ideas on how to improve the above to solve problem on server?