samedi 26 septembre 2015

Implementing Checkboxes and Radio Buttons for fillable text using iText Library

I have searched to the seventh page of Google for this and I simply CANNOT FIND ANSWERS! I am using text to allow the user to edit a form, which contains radio buttons and checkboxes, however when I run the app, it has no effect on the pdf that is generated and mailed. This is my snippet of code to get when the checkboxes and radio buttons are checked:

PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(file));
                final AcroFields acroFields = stamper.getAcroFields();
if (checkBox.isChecked()) {
                    acroFields.setField("rf", String.valueOf(true));
                } else if (checkBox2.isChecked()) {
                    acroFields.setField("rwd",String.valueOf(true));
                } else if (checkBox3.isChecked()) {
                    acroFields.setField("ca", String.valueOf(true));
                } else if (checkBox4.isChecked()) {
                    acroFields.setField("lt", String.valueOf(true));
                } else if (checkBox5.isChecked()) {
                    acroFields.setField("d", String.valueOf(true));
                } else if (checkBox6.isChecked()) {
                    acroFields.setField("o", String.valueOf(true));
                }
                radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(RadioGroup group, int checkedId) {
                        if(radioButton.isChecked()){
                            try {
                                acroFields.setField("male",String.valueOf(true));
                            } catch (IOException e) {
                                e.printStackTrace();
                            } catch (DocumentException e) {
                                e.printStackTrace();
                            }
                        }else if (radioButton2.isChecked()){
                            try {
                                acroFields.setField("female",String.valueOf(true));
                            } catch (IOException e) {
                                e.printStackTrace();
                            } catch (DocumentException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                });


                stamper.setFormFlattening(true);
                //stamper.getAcroFields();
                stamper.close();
            } catch (DocumentException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            reader.close();
            //document.add();

        }
    });

I also tried replacing

String.valueOf(true)

with

"on"

but none made changes to the fillable pdf after i mailed it to myself. What am i doing wrong? And is there some other method to make the checkboxes or radio buttons checked show on the pdf?




Aucun commentaire:

Enregistrer un commentaire