You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Barry Neu <ba...@gmail.com> on 2016/06/13 17:32:17 UTC

PDField - How to calculate the pixel capacity of a text field?

Hello.

Is it possible to calculate the pixel width of a text field on a fillable PDF?
If so, is there an example available or where can I look to research?

Some context:
I’m working with PDFBox 2.0.
Data for a fillable form is collected in a web user interface. If the value for a given field exceeds the field capacity on the form, the value should be populated on an addendum form. The font size of the field cannot scale down below a particular value.

The font and font size are known in advance so the length of the Value can be calculated. But I need to know the pixel capacity of the field to know if the value will “fit”. 
Also open to an alternate strategy if someone has solved differently.

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


Re: PDField - How to calculate the pixel capacity of a text field?

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

> Am 14.06.2016 um 08:38 schrieb Magnus Evensberget <ma...@gmail.com>:
> 
> We solved this by this code:
> 
> public Optional<Integer> getMaxLengthOfField(PDAcroForm form, String
> fieldName) {
>  if(hasField(form, fieldName)) {
>    PDTextField field = getTextField(form, fieldName).get();
>    if(field != null) {
>      PDFont font = PDType1Font.COURIER;
>      int fontSize = getFontSizeFromAppearance(field.getDefaultAppearance());
>      float oneCharWidth = (font.getAverageFontWidth() /
> PDF_FONT_WIDTH_UNIT) * fontSize;
> 
>      COSDictionary dict = field.getCOSObject();
>      COSBase box = dict.getObjectFromPath("AP/N/BBox");
>      if (!(box instanceof COSArray)) {
>        box = dict.getItem(COSName.RECT);
>      }
>      if (box instanceof COSArray) {
>        COSArray rect = (COSArray)box;
>        float fieldWidth = ((COSFloat)rect.get(2)).floatValue() -
> ((COSFloat)rect.get(0)).floatValue();
> 
>        int maxLength = (int)Math.floor(fieldWidth / oneCharWidth);
>        return Optional.of(maxLength);
>      }
>    }
>  }
>  return Optional.absent();
> }
> 
> This only work with fonts where all characters are equally wide (such as
> Courier)
> 

you can get the width of a string using PDFont.getStringWidth(String text) see 

http://pdfbox.apache.org/docs/2.0.2/javadocs/org/apache/pdfbox/pdmodel/font/PDFont.html#getStringWidth(java.lang.String)

also works for proportional fonts.

BR
Maruan


> 
> 
> On Mon, 13 Jun 2016 at 22:50 Tilman Hausherr <TH...@t-online.de> wrote:
> 
>> Am 13.06.2016 um 22:36 schrieb Barry Neu:
>>> Thank you for the reply.
>>> I could store meta data about the fields’ capacity as a last resort.
>> However, there are about 50 different forms to work with and the number
>> will continue to grow.
>>> 
>>> Including Tilman’s reply here:
>>>      "Calculate the width of the /Rectangle. 1 unit = 1/72 inch.”
>>> 
>>> Are the /Rect coordinates represented in the following order?
>>> Left rectangle boundary, Top, Right, Bottom
>>> 
>>> So, 91.095 - 51.855 = 39.24/72s inch wide (or a little over a 1/2 inch)??
>>> 
>>> And, how does one get to the /Rect data?
>> 
>> Get the widgets of the field
>> 
>> PDField.getWidgets(). Usually there is only one (unless you have several
>> widgets, i.e. that the field appears several times in the PDF. So do
>> this call:
>> 
>> getWidgets().get(0).getRectangle().getWidth()
>> 
>> What is in the PDF shouldn't matter, unless for debugging. I.e. don't
>> try to parse the PDF yourself.
>> 
>> I suggest you have a look at the examples in the source download,
>> especially in org.apache.pdfbox.examples.interactive.form.
>> 
>> Tilman
>> 
>>> I have a debug session open in Eclipse but am not seeing the /Rect data
>> in ether the PDField or PDAcroForm.
>>> 
>>>> On Jun 13, 2016, at 12:32 PM, Aaron Mulder <am...@gmail.com> wrote:
>>>> 
>>>> If the form isn't changing, can you just check out the field
>>>> definition in the PDF doc?  Here's one from the PDF form I'm working
>>>> with:
>>>> 
>>>> << /Type /Annot /T (SlotsTotal 19) /V () /Rect [ 51.855 457.452 91.095
>> 478.332
>>>> ] /DV () /FT /Tx /DA (/Helvetica 12 Tf 0 g) /F 4 /MK 1972 0 R /Q 1
>> /Subtype
>>>> /Widget >>
>>>> 
>>>> The /Rect units aren't in pixels but I assume the text width
>>>> calculation would be the same so it would work out.
>>>> 
>>>> My PDF was originally a Linearized mess but I opened it and saved it
>>>> in Preview on OS X and then all the form elements came out in plain
>>>> text which made it easy to inspect in a text editor.
>>>> 
>>>> Thanks,
>>>>      Aaron
>>>> 
>>>> 
>>>> On Mon, Jun 13, 2016 at 1:32 PM, Barry Neu <ba...@gmail.com> wrote:
>>>>> Hello.
>>>>> 
>>>>> Is it possible to calculate the pixel width of a text field on a
>> fillable PDF?
>>>>> If so, is there an example available or where can I look to research?
>>>>> 
>>>>> Some context:
>>>>> I’m working with PDFBox 2.0.
>>>>> Data for a fillable form is collected in a web user interface. If the
>> value for a given field exceeds the field capacity on the form, the value
>> should be populated on an addendum form. The font size of the field cannot
>> scale down below a particular value.
>>>>> 
>>>>> The font and font size are known in advance so the length of the Value
>> can be calculated. But I need to know the pixel capacity of the field to
>> know if the value will “fit”.
>>>>> Also open to an alternate strategy if someone has solved differently.
>>>>> 
>>>>> Thanks for any help.
>>>>> ---------------------------------------------------------------------
>>>>> 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
>> 
>> 


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


Re: PDField - How to calculate the pixel capacity of a text field?

Posted by Magnus Evensberget <ma...@gmail.com>.
We solved this by this code:

public Optional<Integer> getMaxLengthOfField(PDAcroForm form, String
fieldName) {
  if(hasField(form, fieldName)) {
    PDTextField field = getTextField(form, fieldName).get();
    if(field != null) {
      PDFont font = PDType1Font.COURIER;
      int fontSize = getFontSizeFromAppearance(field.getDefaultAppearance());
      float oneCharWidth = (font.getAverageFontWidth() /
PDF_FONT_WIDTH_UNIT) * fontSize;

      COSDictionary dict = field.getCOSObject();
      COSBase box = dict.getObjectFromPath("AP/N/BBox");
      if (!(box instanceof COSArray)) {
        box = dict.getItem(COSName.RECT);
      }
      if (box instanceof COSArray) {
        COSArray rect = (COSArray)box;
        float fieldWidth = ((COSFloat)rect.get(2)).floatValue() -
((COSFloat)rect.get(0)).floatValue();

        int maxLength = (int)Math.floor(fieldWidth / oneCharWidth);
        return Optional.of(maxLength);
      }
    }
  }
  return Optional.absent();
}

This only work with fonts where all characters are equally wide (such as
Courier)



On Mon, 13 Jun 2016 at 22:50 Tilman Hausherr <TH...@t-online.de> wrote:

> Am 13.06.2016 um 22:36 schrieb Barry Neu:
> > Thank you for the reply.
> > I could store meta data about the fields’ capacity as a last resort.
> However, there are about 50 different forms to work with and the number
> will continue to grow.
> >
> > Including Tilman’s reply here:
> >       "Calculate the width of the /Rectangle. 1 unit = 1/72 inch.”
> >
> > Are the /Rect coordinates represented in the following order?
> > Left rectangle boundary, Top, Right, Bottom
> >
> > So, 91.095 - 51.855 = 39.24/72s inch wide (or a little over a 1/2 inch)??
> >
> > And, how does one get to the /Rect data?
>
> Get the widgets of the field
>
> PDField.getWidgets(). Usually there is only one (unless you have several
> widgets, i.e. that the field appears several times in the PDF. So do
> this call:
>
> getWidgets().get(0).getRectangle().getWidth()
>
> What is in the PDF shouldn't matter, unless for debugging. I.e. don't
> try to parse the PDF yourself.
>
> I suggest you have a look at the examples in the source download,
> especially in org.apache.pdfbox.examples.interactive.form.
>
> Tilman
>
> > I have a debug session open in Eclipse but am not seeing the /Rect data
> in ether the PDField or PDAcroForm.
> >
> >> On Jun 13, 2016, at 12:32 PM, Aaron Mulder <am...@gmail.com> wrote:
> >>
> >> If the form isn't changing, can you just check out the field
> >> definition in the PDF doc?  Here's one from the PDF form I'm working
> >> with:
> >>
> >> << /Type /Annot /T (SlotsTotal 19) /V () /Rect [ 51.855 457.452 91.095
> 478.332
> >> ] /DV () /FT /Tx /DA (/Helvetica 12 Tf 0 g) /F 4 /MK 1972 0 R /Q 1
> /Subtype
> >> /Widget >>
> >>
> >> The /Rect units aren't in pixels but I assume the text width
> >> calculation would be the same so it would work out.
> >>
> >> My PDF was originally a Linearized mess but I opened it and saved it
> >> in Preview on OS X and then all the form elements came out in plain
> >> text which made it easy to inspect in a text editor.
> >>
> >> Thanks,
> >>       Aaron
> >>
> >>
> >> On Mon, Jun 13, 2016 at 1:32 PM, Barry Neu <ba...@gmail.com> wrote:
> >>> Hello.
> >>>
> >>> Is it possible to calculate the pixel width of a text field on a
> fillable PDF?
> >>> If so, is there an example available or where can I look to research?
> >>>
> >>> Some context:
> >>> I’m working with PDFBox 2.0.
> >>> Data for a fillable form is collected in a web user interface. If the
> value for a given field exceeds the field capacity on the form, the value
> should be populated on an addendum form. The font size of the field cannot
> scale down below a particular value.
> >>>
> >>> The font and font size are known in advance so the length of the Value
> can be calculated. But I need to know the pixel capacity of the field to
> know if the value will “fit”.
> >>> Also open to an alternate strategy if someone has solved differently.
> >>>
> >>> Thanks for any help.
> >>> ---------------------------------------------------------------------
> >>> 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: PDField - How to calculate the pixel capacity of a text field?

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

here is a quick sample program - hope it helps.


	// Load the PDF document created by SimpleForm.java
        PDDocument document = PDDocument.load(new File("target/SimpleForm.pdf"));
        PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
        
        // Get the field and the widget associated to it.
        // Note: there might be multiple widgets
        PDField field = acroForm.getField("SampleField");
        PDAnnotationWidget widget = field.getWidgets().get(0);
        
        // Get the width of the fields box
        float widthOfField = widget.getRectangle().getWidth();
        
        // Get the font and the font size setting
        // This is currently a little awkward and needs improvement to have a better API
        // for that. In many cases the string will be built like that:
        //    /Helv 12 Tf 0 g
        // We could use PDFStreamParser to do the parsing. For the sample we split the
        // string.
        String defaultAppearance = ((PDTextField) field).getDefaultAppearance();
        String[] parts = defaultAppearance.split(" ");
        
        // Get the font name 
        COSName fontName = COSName.getPDFName(parts[0].substring(1));
        float fontSize = Float.parseFloat(parts[1]);
        
        // Get the font resource.
        // First look up the font from the widgets appearance stream.
        // This will be the case if there is already a value.
        // If the value hasn't been set yet the font resource needs to be looked up from
        // the AcroForm default resources
        
        PDFont font = null;
        PDResources resources = null;
        
        resources = widget.getNormalAppearanceStream().getResources();
        if (resources != null)
        {
            font = resources.getFont(fontName);
        }
        if (font == null)
        {
            font = acroForm.getDefaultResources().getFont(fontName);
        }
        
        String willFit = "short string";
        String willNotFit = "this is a very long string which will not fit the width of the widget";
        
        // calculate the string width at a certain font size
        float willFitWidth = font.getStringWidth(willFit) * fontSize / 1000;
        float willNotFitWidth = font.getStringWidth(willNotFit) * fontSize / 1000;
        
        assert willFitWidth < widthOfField;
        assert willNotFitWidth > widthOfField;
        
        document.close();




BR
Maruan

> Am 17.06.2016 um 18:03 schrieb Tilman Hausherr <TH...@t-online.de>:
> 
> Am 16.06.2016 um 23:12 schrieb Barry Neu:
>> Given an earlier reply from Maruan:
>> "you can get the width of a string using PDFont.getStringWidth(String text)"
> 
> Yes this is true.
> 
>> Is it not true one needs to know the font size to determine the string width?
> 
> Yes that too. If you have a size 12 then multiply with 12. And divide by 1000 (this is only for string widths):
> 
> float stringWidth = font.getStringWidth( message )*fontSize/1000f;
> 
> (This is from the CreateLandscapePDF example)
> 
> If your font is size 12: 2780 * 12 / 1000 / 72 * 2.54 = 1.17cm
> 
> To decide whether it will fit in your rectangle, just use
> 
> 2780 * 12 / 1000 = 33.36
> 
> Sorry that this doesn't really go forward. If you have a PDF and a minimal software maybe we can help better.
> 
> Tilman
> 
> 
>> My goal is to determine if a field value will fit in a field at the specified font size on the form.
>> ...
>> //get field size - 1 unit = 1/72 inch
>> float fieldSize = field.getWidgets().get(0).getRectangle().getWidth();
>> 
>> //get field value size
>> PDFont font = PDType1Font.HELVETICA;
>> float fieldLength = font.getStringWidth(someValue);
>> ...
>> 
>> 1. How can an accurate length be calculated without a Font Size??
>> 2. And, the getStringWidth() method returns a value such as 2780.0 for a 5 character field .. what does that number represent?
> 
> 
> 
>> Thanks again.
>> 
>> 
>> 
>>> On Jun 16, 2016, at 2:19 PM, Tilman Hausherr<TH...@t-online.de>  wrote:
>>> 
>>> Am 16.06.2016 um 20:56 schrieb Barry Neu:
>>>> Thank you Tilman.
>>>> 
>>>> I was poking around trying to find where to get the Font and Font size for a PDTextField but not having any luck.
>>>> Is it in the CosDictionary or what is the proper way to find those 2 pieces of information?
>>> getDefaultAppearance()
>>> 
>>> you would have to parse that.
>>> 
>>> I see there's also getDefaultAppearanceString() which is more advanced, but this isn't public. See the source code of PDDefaultAppearanceString to see what can be done with that, and make a copy for yourself.
>>> 
>>>    PDDefaultAppearanceString getDefaultAppearanceString() throws IOException
>>>    {
>>>        COSString da = (COSString) getInheritableAttribute(COSName.DA);
>>>        PDResources dr = getAcroForm().getDefaultResources();
>>>        return new PDDefaultAppearanceString(da, dr);
>>>    }
>>> 
>>> 
>>> Tilman
>>> 
>>> 
>>>> Really appreciate the support.
>>>> 
>>>>> On Jun 13, 2016, at 2:51 PM, Tilman Hausherr<TH...@t-online.de>  wrote:
>>>>> 
>>>>> Am 13.06.2016 um 22:36 schrieb Barry Neu:
>>>>>> Thank you for the reply.
>>>>>> I could store meta data about the fields’ capacity as a last resort. However, there are about 50 different forms to work with and the number will continue to grow.
>>>>>> 
>>>>>> Including Tilman’s reply here:
>>>>>> 	"Calculate the width of the /Rectangle. 1 unit = 1/72 inch.”
>>>>>> 
>>>>>> Are the /Rect coordinates represented in the following order?
>>>>>> Left rectangle boundary, Top, Right, Bottom
>>>>>> 
>>>>>> So, 91.095 - 51.855 = 39.24/72s inch wide (or a little over a 1/2 inch)??
>>>>>> 
>>>>>> And, how does one get to the /Rect data?
>>>>> Get the widgets of the field
>>>>> 
>>>>> PDField.getWidgets(). Usually there is only one (unless you have several widgets, i.e. that the field appears several times in the PDF. So do this call:
>>>>> 
>>>>> getWidgets().get(0).getRectangle().getWidth()
>>>>> 
>>>>> What is in the PDF shouldn't matter, unless for debugging. I.e. don't try to parse the PDF yourself.
>>>>> 
>>>>> I suggest you have a look at the examples in the source download, especially in org.apache.pdfbox.examples.interactive.form.
>>>>> 
>>>>> Tilman
>>>>> 
>>>>>> I have a debug session open in Eclipse but am not seeing the /Rect data in ether the PDField or PDAcroForm.
>>>>>> 
>>>>>>> On Jun 13, 2016, at 12:32 PM, Aaron Mulder<am...@gmail.com>  wrote:
>>>>>>> 
>>>>>>> If the form isn't changing, can you just check out the field
>>>>>>> definition in the PDF doc?  Here's one from the PDF form I'm working
>>>>>>> with:
>>>>>>> 
>>>>>>> << /Type /Annot /T (SlotsTotal 19) /V () /Rect [ 51.855 457.452 91.095 478.332
>>>>>>> ] /DV () /FT /Tx /DA (/Helvetica 12 Tf 0 g) /F 4 /MK 1972 0 R /Q 1 /Subtype
>>>>>>> /Widget >>
>>>>>>> 
>>>>>>> The /Rect units aren't in pixels but I assume the text width
>>>>>>> calculation would be the same so it would work out.
>>>>>>> 
>>>>>>> My PDF was originally a Linearized mess but I opened it and saved it
>>>>>>> in Preview on OS X and then all the form elements came out in plain
>>>>>>> text which made it easy to inspect in a text editor.
>>>>>>> 
>>>>>>> Thanks,
>>>>>>>      Aaron
>>>>>>> 
>>>>>>> 
>>>>>>> On Mon, Jun 13, 2016 at 1:32 PM, Barry Neu<ba...@gmail.com>  wrote:
>>>>>>>> Hello.
>>>>>>>> 
>>>>>>>> Is it possible to calculate the pixel width of a text field on a fillable PDF?
>>>>>>>> If so, is there an example available or where can I look to research?
>>>>>>>> 
>>>>>>>> Some context:
>>>>>>>> I’m working with PDFBox 2.0.
>>>>>>>> Data for a fillable form is collected in a web user interface. If the value for a given field exceeds the field capacity on the form, the value should be populated on an addendum form. The font size of the field cannot scale down below a particular value.
>>>>>>>> 
>>>>>>>> The font and font size are known in advance so the length of the Value can be calculated. But I need to know the pixel capacity of the field to know if the value will “fit”.
>>>>>>>> Also open to an alternate strategy if someone has solved differently.
>>>>>>>> 
>>>>>>>> Thanks for any help.
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> 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
>>>>> 
>>>> ---------------------------------------------------------------------
>>>> 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: PDField - How to calculate the pixel capacity of a text field?

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 16.06.2016 um 23:12 schrieb Barry Neu:
> Given an earlier reply from Maruan:
> "you can get the width of a string using PDFont.getStringWidth(String text)"

Yes this is true.

> Is it not true one needs to know the font size to determine the string width?

Yes that too. If you have a size 12 then multiply with 12. And divide by 
1000 (this is only for string widths):

float stringWidth = font.getStringWidth( message )*fontSize/1000f;

(This is from the CreateLandscapePDF example)

If your font is size 12: 2780 * 12 / 1000 / 72 * 2.54 = 1.17cm

To decide whether it will fit in your rectangle, just use

2780 * 12 / 1000 = 33.36

Sorry that this doesn't really go forward. If you have a PDF and a 
minimal software maybe we can help better.

Tilman


> My goal is to determine if a field value will fit in a field at the specified font size on the form.
> ...
> //get field size - 1 unit = 1/72 inch
> float fieldSize = field.getWidgets().get(0).getRectangle().getWidth();
>
> //get field value size
> PDFont font = PDType1Font.HELVETICA;
> float fieldLength = font.getStringWidth(someValue);
> ...
>
> 1. How can an accurate length be calculated without a Font Size??
> 2. And, the getStringWidth() method returns a value such as 2780.0 for a 5 character field .. what does that number represent?



> Thanks again.
>
>
>
>> On Jun 16, 2016, at 2:19 PM, Tilman Hausherr<TH...@t-online.de>  wrote:
>>
>> Am 16.06.2016 um 20:56 schrieb Barry Neu:
>>> Thank you Tilman.
>>>
>>> I was poking around trying to find where to get the Font and Font size for a PDTextField but not having any luck.
>>> Is it in the CosDictionary or what is the proper way to find those 2 pieces of information?
>> getDefaultAppearance()
>>
>> you would have to parse that.
>>
>> I see there's also getDefaultAppearanceString() which is more advanced, but this isn't public. See the source code of PDDefaultAppearanceString to see what can be done with that, and make a copy for yourself.
>>
>>     PDDefaultAppearanceString getDefaultAppearanceString() throws IOException
>>     {
>>         COSString da = (COSString) getInheritableAttribute(COSName.DA);
>>         PDResources dr = getAcroForm().getDefaultResources();
>>         return new PDDefaultAppearanceString(da, dr);
>>     }
>>
>>
>> Tilman
>>
>>
>>> Really appreciate the support.
>>>
>>>> On Jun 13, 2016, at 2:51 PM, Tilman Hausherr<TH...@t-online.de>  wrote:
>>>>
>>>> Am 13.06.2016 um 22:36 schrieb Barry Neu:
>>>>> Thank you for the reply.
>>>>> I could store meta data about the fields\u2019 capacity as a last resort. However, there are about 50 different forms to work with and the number will continue to grow.
>>>>>
>>>>> Including Tilman\u2019s reply here:
>>>>> 	"Calculate the width of the /Rectangle. 1 unit = 1/72 inch.\u201d
>>>>>
>>>>> Are the /Rect coordinates represented in the following order?
>>>>> Left rectangle boundary, Top, Right, Bottom
>>>>>
>>>>> So, 91.095 - 51.855 = 39.24/72s inch wide (or a little over a 1/2 inch)??
>>>>>
>>>>> And, how does one get to the /Rect data?
>>>> Get the widgets of the field
>>>>
>>>> PDField.getWidgets(). Usually there is only one (unless you have several widgets, i.e. that the field appears several times in the PDF. So do this call:
>>>>
>>>> getWidgets().get(0).getRectangle().getWidth()
>>>>
>>>> What is in the PDF shouldn't matter, unless for debugging. I.e. don't try to parse the PDF yourself.
>>>>
>>>> I suggest you have a look at the examples in the source download, especially in org.apache.pdfbox.examples.interactive.form.
>>>>
>>>> Tilman
>>>>
>>>>> I have a debug session open in Eclipse but am not seeing the /Rect data in ether the PDField or PDAcroForm.
>>>>>
>>>>>> On Jun 13, 2016, at 12:32 PM, Aaron Mulder<am...@gmail.com>  wrote:
>>>>>>
>>>>>> If the form isn't changing, can you just check out the field
>>>>>> definition in the PDF doc?  Here's one from the PDF form I'm working
>>>>>> with:
>>>>>>
>>>>>> << /Type /Annot /T (SlotsTotal 19) /V () /Rect [ 51.855 457.452 91.095 478.332
>>>>>> ] /DV () /FT /Tx /DA (/Helvetica 12 Tf 0 g) /F 4 /MK 1972 0 R /Q 1 /Subtype
>>>>>> /Widget >>
>>>>>>
>>>>>> The /Rect units aren't in pixels but I assume the text width
>>>>>> calculation would be the same so it would work out.
>>>>>>
>>>>>> My PDF was originally a Linearized mess but I opened it and saved it
>>>>>> in Preview on OS X and then all the form elements came out in plain
>>>>>> text which made it easy to inspect in a text editor.
>>>>>>
>>>>>> Thanks,
>>>>>>       Aaron
>>>>>>
>>>>>>
>>>>>> On Mon, Jun 13, 2016 at 1:32 PM, Barry Neu<ba...@gmail.com>  wrote:
>>>>>>> Hello.
>>>>>>>
>>>>>>> Is it possible to calculate the pixel width of a text field on a fillable PDF?
>>>>>>> If so, is there an example available or where can I look to research?
>>>>>>>
>>>>>>> Some context:
>>>>>>> I\u2019m working with PDFBox 2.0.
>>>>>>> Data for a fillable form is collected in a web user interface. If the value for a given field exceeds the field capacity on the form, the value should be populated on an addendum form. The font size of the field cannot scale down below a particular value.
>>>>>>>
>>>>>>> The font and font size are known in advance so the length of the Value can be calculated. But I need to know the pixel capacity of the field to know if the value will \u201cfit\u201d.
>>>>>>> Also open to an alternate strategy if someone has solved differently.
>>>>>>>
>>>>>>> Thanks for any help.
>>>>>>> ---------------------------------------------------------------------
>>>>>>> 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
>>>>
>>> ---------------------------------------------------------------------
>>> 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: PDField - How to calculate the pixel capacity of a text field?

Posted by Barry Neu <ba...@gmail.com>.
Given an earlier reply from Maruan:
"you can get the width of a string using PDFont.getStringWidth(String text)"

Is it not true one needs to know the font size to determine the string width?

My goal is to determine if a field value will fit in a field at the specified font size on the form.
...
//get field size - 1 unit = 1/72 inch
float fieldSize = field.getWidgets().get(0).getRectangle().getWidth();

//get field value size
PDFont font = PDType1Font.HELVETICA;
float fieldLength = font.getStringWidth(someValue);
...

1. How can an accurate length be calculated without a Font Size??
2. And, the getStringWidth() method returns a value such as 2780.0 for a 5 character field .. what does that number represent?

Thanks again.



> On Jun 16, 2016, at 2:19 PM, Tilman Hausherr <TH...@t-online.de> wrote:
> 
> Am 16.06.2016 um 20:56 schrieb Barry Neu:
>> Thank you Tilman.
>> 
>> I was poking around trying to find where to get the Font and Font size for a PDTextField but not having any luck.
>> Is it in the CosDictionary or what is the proper way to find those 2 pieces of information?
> 
> getDefaultAppearance()
> 
> you would have to parse that.
> 
> I see there's also getDefaultAppearanceString() which is more advanced, but this isn't public. See the source code of PDDefaultAppearanceString to see what can be done with that, and make a copy for yourself.
> 
>    PDDefaultAppearanceString getDefaultAppearanceString() throws IOException
>    {
>        COSString da = (COSString) getInheritableAttribute(COSName.DA);
>        PDResources dr = getAcroForm().getDefaultResources();
>        return new PDDefaultAppearanceString(da, dr);
>    }
> 
> 
> Tilman
> 
> 
>> 
>> Really appreciate the support.
>> 
>>> On Jun 13, 2016, at 2:51 PM, Tilman Hausherr <TH...@t-online.de> wrote:
>>> 
>>> Am 13.06.2016 um 22:36 schrieb Barry Neu:
>>>> Thank you for the reply.
>>>> I could store meta data about the fields’ capacity as a last resort. However, there are about 50 different forms to work with and the number will continue to grow.
>>>> 
>>>> Including Tilman’s reply here:
>>>> 	"Calculate the width of the /Rectangle. 1 unit = 1/72 inch.”
>>>> 
>>>> Are the /Rect coordinates represented in the following order?
>>>> Left rectangle boundary, Top, Right, Bottom
>>>> 
>>>> So, 91.095 - 51.855 = 39.24/72s inch wide (or a little over a 1/2 inch)??
>>>> 
>>>> And, how does one get to the /Rect data?
>>> Get the widgets of the field
>>> 
>>> PDField.getWidgets(). Usually there is only one (unless you have several widgets, i.e. that the field appears several times in the PDF. So do this call:
>>> 
>>> getWidgets().get(0).getRectangle().getWidth()
>>> 
>>> What is in the PDF shouldn't matter, unless for debugging. I.e. don't try to parse the PDF yourself.
>>> 
>>> I suggest you have a look at the examples in the source download, especially in org.apache.pdfbox.examples.interactive.form.
>>> 
>>> Tilman
>>> 
>>>> I have a debug session open in Eclipse but am not seeing the /Rect data in ether the PDField or PDAcroForm.
>>>> 
>>>>> On Jun 13, 2016, at 12:32 PM, Aaron Mulder <am...@gmail.com> wrote:
>>>>> 
>>>>> If the form isn't changing, can you just check out the field
>>>>> definition in the PDF doc?  Here's one from the PDF form I'm working
>>>>> with:
>>>>> 
>>>>> << /Type /Annot /T (SlotsTotal 19) /V () /Rect [ 51.855 457.452 91.095 478.332
>>>>> ] /DV () /FT /Tx /DA (/Helvetica 12 Tf 0 g) /F 4 /MK 1972 0 R /Q 1 /Subtype
>>>>> /Widget >>
>>>>> 
>>>>> The /Rect units aren't in pixels but I assume the text width
>>>>> calculation would be the same so it would work out.
>>>>> 
>>>>> My PDF was originally a Linearized mess but I opened it and saved it
>>>>> in Preview on OS X and then all the form elements came out in plain
>>>>> text which made it easy to inspect in a text editor.
>>>>> 
>>>>> Thanks,
>>>>>      Aaron
>>>>> 
>>>>> 
>>>>> On Mon, Jun 13, 2016 at 1:32 PM, Barry Neu <ba...@gmail.com> wrote:
>>>>>> Hello.
>>>>>> 
>>>>>> Is it possible to calculate the pixel width of a text field on a fillable PDF?
>>>>>> If so, is there an example available or where can I look to research?
>>>>>> 
>>>>>> Some context:
>>>>>> I’m working with PDFBox 2.0.
>>>>>> Data for a fillable form is collected in a web user interface. If the value for a given field exceeds the field capacity on the form, the value should be populated on an addendum form. The font size of the field cannot scale down below a particular value.
>>>>>> 
>>>>>> The font and font size are known in advance so the length of the Value can be calculated. But I need to know the pixel capacity of the field to know if the value will “fit”.
>>>>>> Also open to an alternate strategy if someone has solved differently.
>>>>>> 
>>>>>> Thanks for any help.
>>>>>> ---------------------------------------------------------------------
>>>>>> 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
>>> 
>> 
>> ---------------------------------------------------------------------
>> 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: PDField - How to calculate the pixel capacity of a text field?

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 16.06.2016 um 20:56 schrieb Barry Neu:
> Thank you Tilman.
>
> I was poking around trying to find where to get the Font and Font size for a PDTextField but not having any luck.
> Is it in the CosDictionary or what is the proper way to find those 2 pieces of information?

getDefaultAppearance()

you would have to parse that.

I see there's also getDefaultAppearanceString() which is more advanced, 
but this isn't public. See the source code of PDDefaultAppearanceString 
to see what can be done with that, and make a copy for yourself.

     PDDefaultAppearanceString getDefaultAppearanceString() throws 
IOException
     {
         COSString da = (COSString) getInheritableAttribute(COSName.DA);
         PDResources dr = getAcroForm().getDefaultResources();
         return new PDDefaultAppearanceString(da, dr);
     }


Tilman


>
> Really appreciate the support.
>
>> On Jun 13, 2016, at 2:51 PM, Tilman Hausherr <TH...@t-online.de> wrote:
>>
>> Am 13.06.2016 um 22:36 schrieb Barry Neu:
>>> Thank you for the reply.
>>> I could store meta data about the fields\u2019 capacity as a last resort. However, there are about 50 different forms to work with and the number will continue to grow.
>>>
>>> Including Tilman\u2019s reply here:
>>> 	"Calculate the width of the /Rectangle. 1 unit = 1/72 inch.\u201d
>>>
>>> Are the /Rect coordinates represented in the following order?
>>> Left rectangle boundary, Top, Right, Bottom
>>>
>>> So, 91.095 - 51.855 = 39.24/72s inch wide (or a little over a 1/2 inch)??
>>>
>>> And, how does one get to the /Rect data?
>> Get the widgets of the field
>>
>> PDField.getWidgets(). Usually there is only one (unless you have several widgets, i.e. that the field appears several times in the PDF. So do this call:
>>
>> getWidgets().get(0).getRectangle().getWidth()
>>
>> What is in the PDF shouldn't matter, unless for debugging. I.e. don't try to parse the PDF yourself.
>>
>> I suggest you have a look at the examples in the source download, especially in org.apache.pdfbox.examples.interactive.form.
>>
>> Tilman
>>
>>> I have a debug session open in Eclipse but am not seeing the /Rect data in ether the PDField or PDAcroForm.
>>>
>>>> On Jun 13, 2016, at 12:32 PM, Aaron Mulder <am...@gmail.com> wrote:
>>>>
>>>> If the form isn't changing, can you just check out the field
>>>> definition in the PDF doc?  Here's one from the PDF form I'm working
>>>> with:
>>>>
>>>> << /Type /Annot /T (SlotsTotal 19) /V () /Rect [ 51.855 457.452 91.095 478.332
>>>> ] /DV () /FT /Tx /DA (/Helvetica 12 Tf 0 g) /F 4 /MK 1972 0 R /Q 1 /Subtype
>>>> /Widget >>
>>>>
>>>> The /Rect units aren't in pixels but I assume the text width
>>>> calculation would be the same so it would work out.
>>>>
>>>> My PDF was originally a Linearized mess but I opened it and saved it
>>>> in Preview on OS X and then all the form elements came out in plain
>>>> text which made it easy to inspect in a text editor.
>>>>
>>>> Thanks,
>>>>       Aaron
>>>>
>>>>
>>>> On Mon, Jun 13, 2016 at 1:32 PM, Barry Neu <ba...@gmail.com> wrote:
>>>>> Hello.
>>>>>
>>>>> Is it possible to calculate the pixel width of a text field on a fillable PDF?
>>>>> If so, is there an example available or where can I look to research?
>>>>>
>>>>> Some context:
>>>>> I\u2019m working with PDFBox 2.0.
>>>>> Data for a fillable form is collected in a web user interface. If the value for a given field exceeds the field capacity on the form, the value should be populated on an addendum form. The font size of the field cannot scale down below a particular value.
>>>>>
>>>>> The font and font size are known in advance so the length of the Value can be calculated. But I need to know the pixel capacity of the field to know if the value will \u201cfit\u201d.
>>>>> Also open to an alternate strategy if someone has solved differently.
>>>>>
>>>>> Thanks for any help.
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>
>
> ---------------------------------------------------------------------
> 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: PDField - How to calculate the pixel capacity of a text field?

Posted by Barry Neu <ba...@gmail.com>.
Thank you Tilman. 

I was poking around trying to find where to get the Font and Font size for a PDTextField but not having any luck.
Is it in the CosDictionary or what is the proper way to find those 2 pieces of information?

Really appreciate the support.

> On Jun 13, 2016, at 2:51 PM, Tilman Hausherr <TH...@t-online.de> wrote:
> 
> Am 13.06.2016 um 22:36 schrieb Barry Neu:
>> Thank you for the reply.
>> I could store meta data about the fields’ capacity as a last resort. However, there are about 50 different forms to work with and the number will continue to grow.
>> 
>> Including Tilman’s reply here:
>> 	"Calculate the width of the /Rectangle. 1 unit = 1/72 inch.”
>> 
>> Are the /Rect coordinates represented in the following order?
>> Left rectangle boundary, Top, Right, Bottom
>> 
>> So, 91.095 - 51.855 = 39.24/72s inch wide (or a little over a 1/2 inch)??
>> 
>> And, how does one get to the /Rect data?
> 
> Get the widgets of the field
> 
> PDField.getWidgets(). Usually there is only one (unless you have several widgets, i.e. that the field appears several times in the PDF. So do this call:
> 
> getWidgets().get(0).getRectangle().getWidth()
> 
> What is in the PDF shouldn't matter, unless for debugging. I.e. don't try to parse the PDF yourself.
> 
> I suggest you have a look at the examples in the source download, especially in org.apache.pdfbox.examples.interactive.form.
> 
> Tilman
> 
>> I have a debug session open in Eclipse but am not seeing the /Rect data in ether the PDField or PDAcroForm.
>> 
>>> On Jun 13, 2016, at 12:32 PM, Aaron Mulder <am...@gmail.com> wrote:
>>> 
>>> If the form isn't changing, can you just check out the field
>>> definition in the PDF doc?  Here's one from the PDF form I'm working
>>> with:
>>> 
>>> << /Type /Annot /T (SlotsTotal 19) /V () /Rect [ 51.855 457.452 91.095 478.332
>>> ] /DV () /FT /Tx /DA (/Helvetica 12 Tf 0 g) /F 4 /MK 1972 0 R /Q 1 /Subtype
>>> /Widget >>
>>> 
>>> The /Rect units aren't in pixels but I assume the text width
>>> calculation would be the same so it would work out.
>>> 
>>> My PDF was originally a Linearized mess but I opened it and saved it
>>> in Preview on OS X and then all the form elements came out in plain
>>> text which made it easy to inspect in a text editor.
>>> 
>>> Thanks,
>>>      Aaron
>>> 
>>> 
>>> On Mon, Jun 13, 2016 at 1:32 PM, Barry Neu <ba...@gmail.com> wrote:
>>>> Hello.
>>>> 
>>>> Is it possible to calculate the pixel width of a text field on a fillable PDF?
>>>> If so, is there an example available or where can I look to research?
>>>> 
>>>> Some context:
>>>> I’m working with PDFBox 2.0.
>>>> Data for a fillable form is collected in a web user interface. If the value for a given field exceeds the field capacity on the form, the value should be populated on an addendum form. The font size of the field cannot scale down below a particular value.
>>>> 
>>>> The font and font size are known in advance so the length of the Value can be calculated. But I need to know the pixel capacity of the field to know if the value will “fit”.
>>>> Also open to an alternate strategy if someone has solved differently.
>>>> 
>>>> Thanks for any help.
>>>> ---------------------------------------------------------------------
>>>> 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
> 


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


Re: PDField - How to calculate the pixel capacity of a text field?

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 13.06.2016 um 22:36 schrieb Barry Neu:
> Thank you for the reply.
> I could store meta data about the fields\u2019 capacity as a last resort. However, there are about 50 different forms to work with and the number will continue to grow.
>
> Including Tilman\u2019s reply here:
> 	"Calculate the width of the /Rectangle. 1 unit = 1/72 inch.\u201d
>
> Are the /Rect coordinates represented in the following order?
> Left rectangle boundary, Top, Right, Bottom
>
> So, 91.095 - 51.855 = 39.24/72s inch wide (or a little over a 1/2 inch)??
>
> And, how does one get to the /Rect data?

Get the widgets of the field

PDField.getWidgets(). Usually there is only one (unless you have several 
widgets, i.e. that the field appears several times in the PDF. So do 
this call:

getWidgets().get(0).getRectangle().getWidth()

What is in the PDF shouldn't matter, unless for debugging. I.e. don't 
try to parse the PDF yourself.

I suggest you have a look at the examples in the source download, 
especially in org.apache.pdfbox.examples.interactive.form.

Tilman

> I have a debug session open in Eclipse but am not seeing the /Rect data in ether the PDField or PDAcroForm.
>
>> On Jun 13, 2016, at 12:32 PM, Aaron Mulder <am...@gmail.com> wrote:
>>
>> If the form isn't changing, can you just check out the field
>> definition in the PDF doc?  Here's one from the PDF form I'm working
>> with:
>>
>> << /Type /Annot /T (SlotsTotal 19) /V () /Rect [ 51.855 457.452 91.095 478.332
>> ] /DV () /FT /Tx /DA (/Helvetica 12 Tf 0 g) /F 4 /MK 1972 0 R /Q 1 /Subtype
>> /Widget >>
>>
>> The /Rect units aren't in pixels but I assume the text width
>> calculation would be the same so it would work out.
>>
>> My PDF was originally a Linearized mess but I opened it and saved it
>> in Preview on OS X and then all the form elements came out in plain
>> text which made it easy to inspect in a text editor.
>>
>> Thanks,
>>       Aaron
>>
>>
>> On Mon, Jun 13, 2016 at 1:32 PM, Barry Neu <ba...@gmail.com> wrote:
>>> Hello.
>>>
>>> Is it possible to calculate the pixel width of a text field on a fillable PDF?
>>> If so, is there an example available or where can I look to research?
>>>
>>> Some context:
>>> I\u2019m working with PDFBox 2.0.
>>> Data for a fillable form is collected in a web user interface. If the value for a given field exceeds the field capacity on the form, the value should be populated on an addendum form. The font size of the field cannot scale down below a particular value.
>>>
>>> The font and font size are known in advance so the length of the Value can be calculated. But I need to know the pixel capacity of the field to know if the value will \u201cfit\u201d.
>>> Also open to an alternate strategy if someone has solved differently.
>>>
>>> Thanks for any help.
>>> ---------------------------------------------------------------------
>>> 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: PDField - How to calculate the pixel capacity of a text field?

Posted by Barry Neu <ba...@gmail.com>.
Thank you for the reply.
I could store meta data about the fields’ capacity as a last resort. However, there are about 50 different forms to work with and the number will continue to grow.

Including Tilman’s reply here:
	"Calculate the width of the /Rectangle. 1 unit = 1/72 inch.”

Are the /Rect coordinates represented in the following order?
Left rectangle boundary, Top, Right, Bottom

So, 91.095 - 51.855 = 39.24/72s inch wide (or a little over a 1/2 inch)??

And, how does one get to the /Rect data? 
I have a debug session open in Eclipse but am not seeing the /Rect data in ether the PDField or PDAcroForm.

> On Jun 13, 2016, at 12:32 PM, Aaron Mulder <am...@gmail.com> wrote:
> 
> If the form isn't changing, can you just check out the field
> definition in the PDF doc?  Here's one from the PDF form I'm working
> with:
> 
> << /Type /Annot /T (SlotsTotal 19) /V () /Rect [ 51.855 457.452 91.095 478.332
> ] /DV () /FT /Tx /DA (/Helvetica 12 Tf 0 g) /F 4 /MK 1972 0 R /Q 1 /Subtype
> /Widget >>
> 
> The /Rect units aren't in pixels but I assume the text width
> calculation would be the same so it would work out.
> 
> My PDF was originally a Linearized mess but I opened it and saved it
> in Preview on OS X and then all the form elements came out in plain
> text which made it easy to inspect in a text editor.
> 
> Thanks,
>      Aaron
> 
> 
> On Mon, Jun 13, 2016 at 1:32 PM, Barry Neu <ba...@gmail.com> wrote:
>> Hello.
>> 
>> Is it possible to calculate the pixel width of a text field on a fillable PDF?
>> If so, is there an example available or where can I look to research?
>> 
>> Some context:
>> I’m working with PDFBox 2.0.
>> Data for a fillable form is collected in a web user interface. If the value for a given field exceeds the field capacity on the form, the value should be populated on an addendum form. The font size of the field cannot scale down below a particular value.
>> 
>> The font and font size are known in advance so the length of the Value can be calculated. But I need to know the pixel capacity of the field to know if the value will “fit”.
>> Also open to an alternate strategy if someone has solved differently.
>> 
>> Thanks for any help.
>> ---------------------------------------------------------------------
>> 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: PDField - How to calculate the pixel capacity of a text field?

Posted by Aaron Mulder <am...@gmail.com>.
If the form isn't changing, can you just check out the field
definition in the PDF doc?  Here's one from the PDF form I'm working
with:

<< /Type /Annot /T (SlotsTotal 19) /V () /Rect [ 51.855 457.452 91.095 478.332
] /DV () /FT /Tx /DA (/Helvetica 12 Tf 0 g) /F 4 /MK 1972 0 R /Q 1 /Subtype
/Widget >>

The /Rect units aren't in pixels but I assume the text width
calculation would be the same so it would work out.

My PDF was originally a Linearized mess but I opened it and saved it
in Preview on OS X and then all the form elements came out in plain
text which made it easy to inspect in a text editor.

Thanks,
      Aaron


On Mon, Jun 13, 2016 at 1:32 PM, Barry Neu <ba...@gmail.com> wrote:
> Hello.
>
> Is it possible to calculate the pixel width of a text field on a fillable PDF?
> If so, is there an example available or where can I look to research?
>
> Some context:
> I’m working with PDFBox 2.0.
> Data for a fillable form is collected in a web user interface. If the value for a given field exceeds the field capacity on the form, the value should be populated on an addendum form. The font size of the field cannot scale down below a particular value.
>
> The font and font size are known in advance so the length of the Value can be calculated. But I need to know the pixel capacity of the field to know if the value will “fit”.
> Also open to an alternate strategy if someone has solved differently.
>
> Thanks for any help.
> ---------------------------------------------------------------------
> 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: PDField - How to calculate the pixel capacity of a text field?

Posted by Tilman Hausherr <TH...@t-online.de>.
Calculate the width of the /Rectangle. 1 unit = 1/72 inch.

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