pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Completely Remove a Field
Date Tue, 26 Apr 2016 17:02:09 GMT
Am 25.04.2016 um 23:49 schrieb Kevin Ternes:
> 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.

Have a look at PDAcroForm.getFields(). You'll have to work with that, 
and if you don't find your field, call PDNonTerminalField.getChildren() 
on non terminal fields. When you find it, remove your field and reassign 
the list.

To find out whether you got your field, check the name or compare not 
the PDField object, but its getCOSObject() result.

Your solution in the recent mail might still work with a specific PDF, 
but I doubt it will work for all PDFs.

Tilman

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message