Link to home
Start Free TrialLog in
Avatar of wayneray
waynerayFlag for United States of America

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(pathCreated)))
        {
            stamper.FormFlattening = false;
            stamper.AcroFields.Xfa.FillXfaForm(pathXml);

            stamper.Close();
        }

Is there a way of ensure the form is edible after prefilling?
Avatar of Dustin Hopkins
Dustin Hopkins
Flag of United States of America image

Hello wayneray,
Assuming the original xfa was saved with the extended rights. Then you probably just need to create the stamper in append mode.
using (PdfStamper stamper = new PdfStamper(new PdfReader(pathPDF), System.IO.File.OpenWrite(pathCreated), '\0', true))
        {
            stamper.FormFlattening = false;
            stamper.AcroFields.Xfa.FillXfaForm(pathXml);

            stamper.Close();
        }

Open in new window


Hope this helps,
Dustin
Avatar of wayneray

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-ARE.pdf"
        Dim newFile As String = "c:\DAV\forms\prefilled\VBA-21-22-ARE.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("nameofvet[0]", fullName)
        pdfFormFields.SetField("filenumber[0]", vafnum)
        pdfFormFields.SetField("nameofservice[0]", vetgroup)
        pdfFormFields.SetField("jobtitile[0]", claim)
        pdfFormFields.SetField("claimantname[0]", personpresent)
        pdfFormFields.SetField("Eveningphonenumber[0]", otherphone)
        pdfFormFields.SetField("daytime[0]", phone)
        pdfFormFields.SetField("ActiveService1", branchos)
        pdfFormFields.SetField("emailaddress[0]", email)
        pdfFormFields.SetField("SSNno[0]", ssn)


        pdfFormFields.SetField("address[0]", address2)
       

        Dim sTmp As String = "form 21-22 Completed for " + _
        pdfFormFields.GetField("NameUsed")
        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
Avatar of Dustin Hopkins
Dustin Hopkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.