You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "Baker, Ricky" <ri...@ttu.edu> on 2017/04/18 16:40:05 UTC

RE: how to set the field that is used in another calculated field

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

RE: how to set the field that is used in another calculated field

Posted by "Baker, Ricky" <ri...@ttu.edu>.
Maruan, thanks for your help. That gets me everything I need



-----Original Message-----
From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] 
Sent: Wednesday, April 19, 2017 3:48 PM
To: users@pdfbox.apache.org
Subject: Re: how to set the field that is used in another calculated field

Hi,

> Am 19.04.2017 um 22:42 schrieb Baker, Ricky <ri...@ttu.edu>:
> 
> Maruan, I can use the getChildren and see the fields but what method can I use to get the field name? 
> 

PDField.getFullyQualifiedName() and PDField.getPartialName()

Please also take a look at the API documentation https://pdfbox.apache.org/docs/2.0.5/javadocs/org/apache/pdfbox/pdmodel/interactive/form/package-summary.html and the examples in the pdfbox-examples subproject. There are also unit tests which show some of the API usage.

BR
Maruan
 

> 
> Ricky
> 
> 
> 
> -----Original Message-----
> From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] 
> Sent: Wednesday, April 19, 2017 2:45 PM
> To: users@pdfbox.apache.org
> Subject: Re: how to set the field that is used in another calculated field
> 
> Hi,
> 
>> Am 19.04.2017 um 21:25 schrieb Baker, Ricky <ri...@ttu.edu>:
>> 
>> I am trying to user the "getKids" but the method does not show up. I have downloaded all the jars for 2.0.5.
>> 
>> PDField field2 = acroForm.getField('theFieldName');
>> 
>> List theKids = field2.getKids();
> 
> you might have a sample code from PDFBox 1.8.x. getKids() is no longer available.
> 
> To travers the field hierachy you can either use PDAcroForm.getFieldTree or you can check if a field is an instance of
> 
> PDNonTerminalField -> there are child fields PDTerminalField -> there are no child fields
> 
> If you have a PDNonTerminalField i.e. a field which has fields as ancestors then use PDNonTerminalField.getChildren().
> 
> BR
> Maruan
> 
> 
>> 
>> What am I missing to use this feature?
>> 
>> 
>> thanks
>> Ricky
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: how to set the field that is used in another calculated field

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

> Am 19.04.2017 um 22:42 schrieb Baker, Ricky <ri...@ttu.edu>:
> 
> Maruan, I can use the getChildren and see the fields but what method can I use to get the field name? 
> 

PDField.getFullyQualifiedName() and PDField.getPartialName()

Please also take a look at the API documentation https://pdfbox.apache.org/docs/2.0.5/javadocs/org/apache/pdfbox/pdmodel/interactive/form/package-summary.html and the examples in the pdfbox-examples subproject. There are also unit tests which show some of the API usage.

BR
Maruan
 

> 
> Ricky
> 
> 
> 
> -----Original Message-----
> From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] 
> Sent: Wednesday, April 19, 2017 2:45 PM
> To: users@pdfbox.apache.org
> Subject: Re: how to set the field that is used in another calculated field
> 
> Hi,
> 
>> Am 19.04.2017 um 21:25 schrieb Baker, Ricky <ri...@ttu.edu>:
>> 
>> I am trying to user the "getKids" but the method does not show up. I have downloaded all the jars for 2.0.5.
>> 
>> PDField field2 = acroForm.getField('theFieldName');
>> 
>> List theKids = field2.getKids();
> 
> you might have a sample code from PDFBox 1.8.x. getKids() is no longer available.
> 
> To travers the field hierachy you can either use PDAcroForm.getFieldTree or you can check if a field is an instance of
> 
> PDNonTerminalField -> there are child fields PDTerminalField -> there are no child fields
> 
> If you have a PDNonTerminalField i.e. a field which has fields as ancestors then use PDNonTerminalField.getChildren().
> 
> BR
> Maruan
> 
> 
>> 
>> What am I missing to use this feature?
>> 
>> 
>> thanks
>> Ricky
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: how to set the field that is used in another calculated field

Posted by "Baker, Ricky" <ri...@ttu.edu>.
Maruan, I can use the getChildren and see the fields but what method can I use to get the field name? 


Ricky



-----Original Message-----
From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] 
Sent: Wednesday, April 19, 2017 2:45 PM
To: users@pdfbox.apache.org
Subject: Re: how to set the field that is used in another calculated field

Hi,

> Am 19.04.2017 um 21:25 schrieb Baker, Ricky <ri...@ttu.edu>:
> 
> I am trying to user the "getKids" but the method does not show up. I have downloaded all the jars for 2.0.5.
> 
> PDField field2 = acroForm.getField('theFieldName');
> 
> List theKids = field2.getKids();

you might have a sample code from PDFBox 1.8.x. getKids() is no longer available.

To travers the field hierachy you can either use PDAcroForm.getFieldTree or you can check if a field is an instance of

PDNonTerminalField -> there are child fields PDTerminalField -> there are no child fields

If you have a PDNonTerminalField i.e. a field which has fields as ancestors then use PDNonTerminalField.getChildren().

BR
Maruan


> 
> What am I missing to use this feature?
> 
> 
> thanks
> Ricky


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: how to set the field that is used in another calculated field

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

> Am 19.04.2017 um 21:25 schrieb Baker, Ricky <ri...@ttu.edu>:
> 
> I am trying to user the "getKids" but the method does not show up. I have downloaded all the jars for 2.0.5.
> 
> PDField field2 = acroForm.getField('theFieldName');
> 
> List theKids = field2.getKids();

you might have a sample code from PDFBox 1.8.x. getKids() is no longer available.

To travers the field hierachy you can either use PDAcroForm.getFieldTree or you can check if a field is an instance of

PDNonTerminalField -> there are child fields
PDTerminalField -> there are no child fields

If you have a PDNonTerminalField i.e. a field which has fields as ancestors then use PDNonTerminalField.getChildren().

BR
Maruan


> 
> What am I missing to use this feature?
> 
> 
> thanks
> Ricky


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: how to set the field that is used in another calculated field

Posted by "Baker, Ricky" <ri...@ttu.edu>.
I am trying to user the "getKids" but the method does not show up. I have downloaded all the jars for 2.0.5.

PDField field2 = acroForm.getField('theFieldName');

List theKids = field2.getKids();

What am I missing to use this feature?


thanks
Ricky

RE: how to set the field that is used in another calculated field

Posted by "Baker, Ricky" <ri...@ttu.edu>.
That worked and it makes sense how I should use this for this task. We are new to PDFBOX and trying to make it harder than it needed to be.

Thanks for your help

Ricky



-----Original Message-----
From: Maruan Sahyoun [mailto:sahyoun@fileaffairs.de] 
Sent: Tuesday, April 18, 2017 12:11 PM
To: users@pdfbox.apache.org
Subject: Re: how to set the field that is used in another calculated field

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 <ri...@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:sahyoun@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 <ri...@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-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: how to set the field that is used in another calculated field

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
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 <ri...@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:sahyoun@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 <ri...@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-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


RE: how to set the field that is used in another calculated field

Posted by "Baker, Ricky" <ri...@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:sahyoun@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 <ri...@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-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: how to set the field that is used in another calculated field

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

> Am 18.04.2017 um 18:40 schrieb Baker, Ricky <ri...@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-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org