I am trying to understand how to use an existing editable pdf where fields 
"a.1", "a.2" and "a.3" are used to calculate "total.1". I am able to setValue 
but the name is not being set (a.1 is created as 1 etc) in the new pdf and the 
"total.1" is not being changed.  I have searched thru the examples but I have 
not found anything similar to what I am attempting.

    PDDocument finalDoc = new PDDocument()
    String formTemplate = "c:/test_input.pdf";

    List<PDField> fields = new ArrayList<PDField>();


    PDDocument doc = PDDocument.load(new File(formTemplate));
    PDDocumentCatalog docCatalog = doc.getDocumentCatalog();

    PDField field1 = acroForm.getField("a.1");
    def x = field1.getPartialName()
    field1.setValue('123.03')

    PDField field2 = acroForm.getField("a.2");
    field2.setValue('200.00')

    PDField field3 = acroForm.getField("a.3");
    field3.setValue('300.00')

    PDField field4 = acroForm.getField("total.1");
    field4.setValue('0')

    fields.add(field1);
    fields.add(field2);
    fields.add(field3);
    fields.add(field4);

    PDAcroForm finalForm = new PDAcroForm(finalDoc);
    finalDoc.getDocumentCatalog().setAcroForm(finalForm);
    finalForm.setFields(fields);

    finalDoc.save(new File("c:/", "test-output.pdf"));


thanks
Ricky

Reply via email to