You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Maruan Sahyoun <sa...@fileaffairs.de> on 2015/02/20 16:40:39 UTC

Re: PDAppearance.calculateFontSize, PDAppearance.setAppearanceValue

Hi Lorena,

when the form is created there are some layout settings to the form and the form fields, one of which is the font to be used when a field is being filled with data. Form fields in PDF have 2 types of objects attached to it - the field itself, holding things like the fields data, field type … and the fields appearance which is for visually representing the field. In fact a field can have multiple appearances but let's keep it simple.

Let's assume you are filling out a form field. What happens is that the field value is updated and the fields visual representation (the appearance) is updated to reflect the new value. To generate this appearance field properties are read most importantly the the Default Appearance /DA (a kind of style definition) and the Default Resources /DR (e.g. the font to use). The DA needs to point to a DR font entry. Now if the names do not match or the font is not existing in the form you might get that error. I can say more after looking at the form.

If possible you might want to try the PDFBox 2.0 snapshot version as there were some enhancements which at least give a better error message if something is missing. Please be aware that the API for AcroForms has changed a bit in 2.0. 

BR
Maruan

Am 20.02.2015 um 16:27 schrieb Lorena Leishman <lo...@yahoo.com.INVALID>:

> Hi Maruan,
> Thank you for your reply. I am using PDFBox1.8.8. I am really not using any formatting related code. I am just sending data to a PDF. I'll talk to my client about sharing the file.
> This is a sample code of a class I have been using for testing purposes. It works great as long as the field on the PDF is Helvetica size 12
> PDChoiceField field3 = (PDChoiceField) acroForm.getField( "Tu3" );field3.setValue("Deleted");
> PDTextbox field11 = (PDTextbox) acroForm.getField( "ex1" );
> field11.setValue("Bad");
> PDTextbox field4 = (PDTextbox) acroForm.getField( "$$1" );
> field4.setValue("$2000");
> PDTextbox field5 = (PDTextbox) acroForm.getField( "$$2" );
> field5.setValue("$5000");
> PDTextbox field6 = (PDTextbox) acroForm.getField( "ACC_ty3" );field6.setValue("CBNM");PDTextbox field7 = (PDTextbox) acroForm.getField( "ACC_ty5" );field7.setValue("VBSH");   PDTextbox field8 = (PDTextbox) acroForm.getField( "Clients Name" );    if (field8 != null)
>            field8.setValue("John Bytheway");PDTextbox field9 = (PDTextbox) acroForm.getField( "Address 1" );field9.setValue("2000 Wolf Cr.");   PDTextbox field10 = (PDTextbox) acroForm.getField( "Date2" );        if (field10 != null)                      field10.setValue("January 2, 2015");
> 
> Maybe I need to update the fields and format them according to the client's wishes.  This is my first time using PDFBox. I thought that by sending data to x field it would get just inherit the attributes of it. That could be the problem. Helvetica could be a default attribute and when data is sent to a field with fancier formatting it doesn't like it. hmmm.
> Thanks for your help.
> Lorena       From: Maruan Sahyoun <sa...@fileaffairs.de>
> To: users@pdfbox.apache.org; Lorena Leishman <lo...@yahoo.com> 
> Sent: Thursday, February 19, 2015 4:29 PM
> Subject: Re: PDAppearance.calculateFontSize, PDAppearance.setAppearanceValue
> 
> could you upload a sample file to a public location for inspection? What if the field uses e.g. Arial TrueType?
> 
> Which version of PDFBox are you using?
> 
> BR
> Maruan
> 
> 
> 
> Am 19.02.2015 um 19:46 schrieb Lorena Leishman <lo...@yahoo.com.INVALID>:
> 
>> Hello everyone,
>> I am having some error messages when I am trying to set values to some fields in a PDF form. Many of the values are set fine but then I get these error for some fields.
>>   java.lang.NullPointerExceptionpdmodel.interactive.form.PDAppearance.calculateFontSize
>> pdmodel.interactive.form.PDAppearance.setAppearanceValue
>> 
>> I noticed that the fields that get updated have font size = 12 and font type Helvetica. If I manually go to the file and change the fields that are not being updated to size =12, font type Helvetica then it works!!
>> I can not have all the fields be the same size and font type. Is there a way to get around this? and why do I have this problem in first place?
>> Any help would be appreciated. Thanks! 
> 
> 


Re: PDAppearance.calculateFontSize, PDAppearance.setAppearanceValue

Posted by Lorena Leishman <lo...@yahoo.com.INVALID>.
Thank you Maruan. It totally makes sense.
 

     From: Maruan Sahyoun <sa...@fileaffairs.de>
 To: users@pdfbox.apache.org; Lorena Leishman <lo...@yahoo.com> 
 Sent: Friday, February 20, 2015 9:40 AM
 Subject: Re: PDAppearance.calculateFontSize, PDAppearance.setAppearanceValue
   
Hi Lorena,
when the form is created there are some layout settings to the form and the form fields, one of which is the font to be used when a field is being filled with data. Form fields in PDF have 2 types of objects attached to it - the field itself, holding things like the fields data, field type … and the fields appearance which is for visually representing the field. In fact a field can have multiple appearances but let's keep it simple.
Let's assume you are filling out a form field. What happens is that the field value is updated and the fields visual representation (the appearance) is updated to reflect the new value. To generate this appearance field properties are read most importantly the the Default Appearance /DA (a kind of style definition) and the Default Resources /DR (e.g. the font to use). The DA needs to point to a DR font entry. Now if the names do not match or the font is not existing in the form you might get that error. I can say more after looking at the form.
If possible you might want to try the PDFBox 2.0 snapshot version as there were some enhancements which at least give a better error message if something is missing. Please be aware that the API for AcroForms has changed a bit in 2.0. 
BRMaruan



Am 20.02.2015 um 16:27 schrieb Lorena Leishman <lo...@yahoo.com.INVALID>:

Hi Maruan,
Thank you for your reply. I am using PDFBox1.8.8. I am really not using any formatting related code. I am just sending data to a PDF. I'll talk to my client about sharing the file.
This is a sample code of a class I have been using for testing purposes. It works great as long as the field on the PDF is Helvetica size 12
PDChoiceField field3 = (PDChoiceField) acroForm.getField( "Tu3" );field3.setValue("Deleted");
PDTextbox field11 = (PDTextbox) acroForm.getField( "ex1" );
field11.setValue("Bad");
PDTextbox field4 = (PDTextbox) acroForm.getField( "$$1" );
field4.setValue("$2000");
PDTextbox field5 = (PDTextbox) acroForm.getField( "$$2" );
field5.setValue("$5000");
PDTextbox field6 = (PDTextbox) acroForm.getField( "ACC_ty3" );field6.setValue("CBNM");PDTextbox field7 = (PDTextbox) acroForm.getField( "ACC_ty5" );field7.setValue("VBSH");   PDTextbox field8 = (PDTextbox) acroForm.getField( "Clients Name" );    if (field8 != null)
           field8.setValue("John Bytheway");PDTextbox field9 = (PDTextbox) acroForm.getField( "Address 1" );field9.setValue("2000 Wolf Cr.");   PDTextbox field10 = (PDTextbox) acroForm.getField( "Date2" );        if (field10 != null)                      field10.setValue("January 2, 2015");

Maybe I need to update the fields and format them according to the client's wishes.  This is my first time using PDFBox. I thought that by sending data to x field it would get just inherit the attributes of it. That could be the problem. Helvetica could be a default attribute and when data is sent to a field with fancier formatting it doesn't like it. hmmm.
Thanks for your help.
Lorena       From: Maruan Sahyoun <sa...@fileaffairs.de>
 To: users@pdfbox.apache.org; Lorena Leishman <lo...@yahoo.com> 
 Sent: Thursday, February 19, 2015 4:29 PM
 Subject: Re: PDAppearance.calculateFontSize, PDAppearance.setAppearanceValue

could you upload a sample file to a public location for inspection? What if the field uses e.g. Arial TrueType?

Which version of PDFBox are you using?

BR
Maruan



Am 19.02.2015 um 19:46 schrieb Lorena Leishman <lo...@yahoo.com.INVALID>:


Hello everyone,
I am having some error messages when I am trying to set values to some fields in a PDF form. Many of the values are set fine but then I get these error for some fields.
  java.lang.NullPointerExceptionpdmodel.interactive.form.PDAppearance.calculateFontSize
pdmodel.interactive.form.PDAppearance.setAppearanceValue

I noticed that the fields that get updated have font size = 12 and font type Helvetica. If I manually go to the file and change the fields that are not being updated to size =12, font type Helvetica then it works!!
I can not have all the fields be the same size and font type. Is there a way to get around this? and why do I have this problem in first place?
Any help would be appreciated. Thanks!