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/%[email protected]%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

Reply via email to