The code below works as far as it goes.
Until we call PDAcroForm.flatten(), the removed PDField is still accessible.  

So the correct code is:

    COSDictionary formDict = pdAcroForm.getCOSObject();
    COSArray formFieldArray = (COSArray) 
formDict.getDictionaryObject(COSName.FIELDS);
    formFieldArray.removeObject(pdField.getCOSObject());
      //  other operations . . .
   pdAcroForm.flatten(); 


-----Original Message-----
From: Kevin Ternes 
Sent: Monday, April 25, 2016 4:50 PM
To: [email protected]
Subject: Completely Remove a Field

It seems like removing a PDField from a loaded PDDocument would be trivial.
The goal is to remove the field from the form and anything related to that 
field from the displayed PDF.

I have tried just removing the PDField from the List of PDAcroForm.getFields() 
which does not seem to work.

And I have tried digging into the PDAcroForm's dictionary:
    PDField pdField = pdAcroForm.getField("boxAPPL");
    COSDictionary formDict = pdAcroForm.getCOSObject();
    COSArray fieldz = (COSArray) formDict.getDictionaryObject(COSName.FIELDS);
    fieldz.removeObject(pdField.getCOSObject());

which does not appear to work either.

Any is help appreciated.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to