pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JZ Q <ccna2c...@gmail.com>
Subject Fillable Field in PDF
Date Mon, 26 Mar 2018 01:00:15 GMT
 Hi Everyone,

I filled in an interactive PDF document using Pdfbox. It works in the sense
that the right field does get the value, but after it gets saved, it
becomes read-only and can't be manually changed using pdf reader.

I have attached the form for your reference. Thank you.


PDDocument pdfTemplate = PDDocument.load(file);

    PDDocumentCatalog docCatalog = pdfTemplate.getDocumentCatalog();
    PDAcroForm acroForm = docCatalog.getAcroForm();

    // Get field names
    List<PDField> fieldList = acroForm.getFields();

    // String the object array
    String[] fieldArray = new String[fieldList.size()];
    int i = 0;
    for (PDField sField : fieldList) {
        fieldArray[i] = sField.getFullyQualifiedName();
        i++;
    }


    for (String f : fieldArray) {
        PDField field = acroForm.getField(f);

        System.out.println("field is: " + f);
        System.out.println("    type: " + field.getFieldType());

        if (f.contains("area")) {
           field.setValue("York");
        }
    }

    try {
     pdfTemplate.setAllSecurityToBeRemoved(true);
      pdfTemplate.save(output_file);
pdfTemplate.close();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


-- 
Best Wishes,
Jason

Mime
View raw message