OK - please try this modified version of your code as a start String formTemplate = "c:/test_input.pdf";
PDDocument doc = PDDocument.load(new File(formTemplate)); PDDocumentCatalog docCatalog = doc.getDocumentCatalog(); PDAcroForm acroForm = docCatalog.getAcroForm(); PDField field1 = acroForm.getField("a.1"); 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') doc.save(new File("c:/", "test-output.pdf")); BR Maruan > Am 18.04.2017 um 19:04 schrieb Baker, Ricky <ricky.ba...@ttu.edu>: > > > > We want to set the values of the fields a.1, a.2, a.3 which is used to > calculate the field "total" and save the modified document in a new file. > > Ricky > > > > > > -----Original Message----- > From: Maruan Sahyoun [mailto:sahy...@fileaffairs.de] > Sent: Tuesday, April 18, 2017 12:00 PM > To: users@pdfbox.apache.org > Subject: Re: how to set the field that is used in another calculated field > > Hi, > >> Am 18.04.2017 um 18:40 schrieb Baker, Ricky <ricky.ba...@ttu.edu>: >> >> >> 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. > > > I'm not sure I understand what you are trying to achieve. Is it that you'd > like to set the values of the fields a.1, a.2, a.3 and total and save the > modified document in a new file? > >> >> 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"); > > where is acroForm coming from? Hasn't been defined yet. > >> 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); > > are you trying to get the fields from yet another document and put them onto > your template? > > … > > BR > Maruan > > >> >> finalDoc.save(new File("c:/", "test-output.pdf")); >> >> >> thanks >> Ricky > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org > For additional commands, e-mail: users-h...@pdfbox.apache.org > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org > For additional commands, e-mail: users-h...@pdfbox.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org For additional commands, e-mail: users-h...@pdfbox.apache.org