pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Chojecki <i...@rayman2200.de>
Subject Re: Flattening
Date Wed, 23 Jan 2013 14:17:05 GMT
Am 22.01.2013 13:25, schrieb Lukas Baab:
> Hi!
Hi Lukas,

>
> How do I "flatten" a PDF-form (remove the form-field but keep the
> text of the field)?
>
> Jason asked this question already.
> (see
> 
> http://mail-archives.apache.org/mod_mbox/pdfbox-users/201009.mbox/%3C4C9A326F.60902@rayman2200.de%3E)
> The answer was this:
>> a quick way to do this, is to remove the fields from the acrofrom.
>> For this you just need to get the document catalog, then the 
>> acroform and then remove all fields from this acroform.
>> The graphical representation is linked with the annotation and stay 
>> in the document.
>
> So I wrote the following code.
> I can write some text in the form-field. But I donĀ“t know how to
> remove the form-field.
> Any ideas?
>
> Thanks for your help!
> Lukas
>
> [some code]

You will need to get the Fields over the COSDictionary. Try this 
code...

     PDDocument pdDoc = PDDocument.load(new File("E:\\Form-Test.pdf"));
     PDDocumentCatalog pdCatalog = pdDoc.getDocumentCatalog();
     PDAcroForm acroForm = pdCatalog.getAcroForm();

     COSDictionary acroFormDict = acroForm.getDictionary();
     COSArray fields = acroFormDict.getDictionaryObject("Fields");
     fields.clear();

Hope this help.

Best regards
Thomas

Mime
View raw message