0

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, so when the user marks a checkbox on the xml in the app, it checks a checkbox on the pdf. 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?

Aria
  • 389
  • 3
  • 7
  • 25
  • Instead of searching Google (which seems to be the new way people learn things), why don't you simply search [the documentation](http://pages.itextpdf.com/ebook-stackoverflow-questions.html) (which may be the old school way to learn things)? You'll discover this question [Checking off pdf checkbox with itextsharp?](http://stackoverflow.com/questions/19698771/checking-off-pdf-checkbox-with-itextsharp) Needless to explain that I'm old school. – Bruno Lowagie Sep 27 '15 at 11:11
  • Note that your question is confusion: your code looks as if you want to change the value of the check boxes. However, your question sounds as if you want to know the value of the check boxes. Maybe you should clarify. – Bruno Lowagie Sep 27 '15 at 11:14
  • @BrunoLowagie i am trying to check a checkbox on the pdf when the user checks it on the xml i created. sorry for the confusion. – Aria Sep 27 '15 at 16:55
  • OK, did you manage to find the *appearance states*? Those tell you the value you need to check the check box. – Bruno Lowagie Sep 28 '15 at 06:20
  • @Aria-Any suggestions on this question?Im facing same issue. – nik Aug 19 '17 at 09:50

0 Answers0