pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lukas Baab" <19lu...@web.de>
Subject Re: Flattening
Date Thu, 24 Jan 2013 16:20:03 GMT
Hi Thomas,

thanks for your advice!

Unfortunately your advice does not work. If I get the Fields over the COSDictionary (as you
recommend) AdobePdfReader still shows the form-fields. Just PDFBox does not recognise the
form-fields any more.
Do you (or someone else) have any idea whether I have to do something different or something
else (eg. delete some further COSObjects...)?

Any further advice is appreciated!

Thanks and best regards

"Thomas Chojecki" <info@rayman2200.de> 23.01.2013, 15:17h:
> 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

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");

Hope this help.

Best regards

View raw message