You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Robert Meissner <r....@applicationpark.de> on 2015/05/11 11:30:17 UTC

Adding a hidden field to a pDF

Hello,

I need to add new hidden fields to a PDAcroForm. How can i do this?
I already created the following code, that changes the values of 
existing fields, but i need to create new fields and add the to the 
PDAcroForm. The fields should be hidden.

     document = PDDocument.load(req.getInputStream());
                     final PDPage page = (PDPage) 
document.getDocumentCatalog().getAllPages().get(document.getNumberOfPages() 
- 1);
                     final PDAcroForm acroForm = 
document.getDocumentCatalog().getAcroForm();

                     for (final PDField field : (List<PDField>) 
acroForm.getFields()) {
                         PDFieldFactory.createField(acroForm, arg1)
                         switch (field.getFullyQualifiedName()) {
                             case "partnerPk": {
                                 field.setValue("7");
                                 break;
                             }
                             case "glaeubigerPk": {
                                 field.setValue("1");
                                 break;
                             }
                             case "aktePk": {
                                 field.setValue("3");
                                 break;
                             }
                             case "dokumentPk": {
                                 field.setValue("7");
                                 break;
                             }
                             case "partnerId": {
                                 field.setValue("070");
                                 break;
                             }
                             case "glaeubigerId": {
                                 field.setValue("11501");
                                 break;
                             }
                             case "partnerKey": {
                                 field.setValue("BOB");
                                 field.setReadonly(true);
                                 break;
                             }
                             default:
                         }
                     }
                     document.save("Z:/1.pdf");
                     document.close();

Thanks for your reply in advance!

Best regards,
RoMe

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