wayneray
asked on
Some PDF Forms no longer editable after prefilling in vb.net application
I created a vb.net app that prefills 10 Veterans forms. The program uses the itextSharp library. All of the forms are editable after prefilling on my computer but I have Adobe Reader/Writer licensed edition on my computer.
When I compiled the code and put the program on another computer that only has the free version of Adobe reader, some of the forms are no longer editable. I use this block of code on all forms.
using (PdfStamper stamper = new PdfStamper(new PdfReader(pathPDF), System.IO.File.OpenWrite(p athCreated )))
{
stamper.FormFlattening = false;
stamper.AcroFields.Xfa.Fil lXfaForm(p athXml);
stamper.Close();
}
Is there a way of ensure the form is edible after prefilling?
When I compiled the code and put the program on another computer that only has the free version of Adobe reader, some of the forms are no longer editable. I use this block of code on all forms.
using (PdfStamper stamper = new PdfStamper(new PdfReader(pathPDF), System.IO.File.OpenWrite(p
{
stamper.FormFlattening = false;
stamper.AcroFields.Xfa.Fil
stamper.Close();
}
Is there a way of ensure the form is edible after prefilling?
ASKER
Dustin, thanks so much for your fast response. Appending sounds like a possible solution. Below is my code that works for some of the 10 forms. Some of the forms however are not editable after prefilling. How would I incorporate your code?
'Dim pdfTemplate As String = "c:\DAV\forms\VBA-21-22-AR E.pdf"
Dim newFile As String = "c:\DAV\forms\prefilled\VB A-21-22-AR E.pdf"
Dim pdfReader As New PdfReader(pdfTemplate)
pdfReader.unethicalreading = True
Dim pdfStamper As New PdfStamper(pdfReader, New FileStream( _
newFile, FileMode.Create))
Dim pdfFormFields As AcroFields = pdfStamper.AcroFields
' set form pdfFormFields
pdfFormFields.SetField("na meofvet[0] ", fullName)
pdfFormFields.SetField("fi lenumber[0 ]", vafnum)
pdfFormFields.SetField("na meofservic e[0]", vetgroup)
pdfFormFields.SetField("jo btitile[0] ", claim)
pdfFormFields.SetField("cl aimantname [0]", personpresent)
pdfFormFields.SetField("Ev eningphone number[0]" , otherphone)
pdfFormFields.SetField("da ytime[0]", phone)
pdfFormFields.SetField("Ac tiveServic e1", branchos)
pdfFormFields.SetField("em ailaddress [0]", email)
pdfFormFields.SetField("SS Nno[0]", ssn)
pdfFormFields.SetField("ad dress[0]", address2)
Dim sTmp As String = "form 21-22 Completed for " + _
pdfFormFields.GetField("Na meUsed")
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()
'Dim pdfTemplate As String = "c:\DAV\forms\VBA-21-22-AR
Dim newFile As String = "c:\DAV\forms\prefilled\VB
Dim pdfReader As New PdfReader(pdfTemplate)
pdfReader.unethicalreading
Dim pdfStamper As New PdfStamper(pdfReader, New FileStream( _
newFile, FileMode.Create))
Dim pdfFormFields As AcroFields = pdfStamper.AcroFields
' set form pdfFormFields
pdfFormFields.SetField("na
pdfFormFields.SetField("fi
pdfFormFields.SetField("na
pdfFormFields.SetField("jo
pdfFormFields.SetField("cl
pdfFormFields.SetField("Ev
pdfFormFields.SetField("da
pdfFormFields.SetField("Ac
pdfFormFields.SetField("em
pdfFormFields.SetField("SS
pdfFormFields.SetField("ad
Dim sTmp As String = "form 21-22 Completed for " + _
pdfFormFields.GetField("Na
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()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dustin, this modified part fixed my problem.
Dim pdfStamper As New PdfStamper(pdfReader, New FileStream( _
newFile, FileMode.Create), "\0", True)
Your are awesome. I know Disabled Vet group that really appreciates your help. The only reason I gave an "A" is because I couldn't put "A+".
Thanks and I will also consider incorporating your other suggestion.
Dim pdfStamper As New PdfStamper(pdfReader, New FileStream( _
newFile, FileMode.Create), "\0", True)
Your are awesome. I know Disabled Vet group that really appreciates your help. The only reason I gave an "A" is because I couldn't put "A+".
Thanks and I will also consider incorporating your other suggestion.
Assuming the original xfa was saved with the extended rights. Then you probably just need to create the stamper in append mode.
Open in new window
Hope this helps,
Dustin