pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maruan Sahyoun <sahy...@fileaffairs.de>
Subject Re: Font AutoSize Issue
Date Fri, 10 Jul 2015 21:28:28 GMT
Hi,

> Am 10.07.2015 um 23:11 schrieb jarrod <xhozst@yahoo.com.INVALID>:
> 
> Hello Maruan,
> 
> I understand what you describing. Its unfortunate it isn't listed in the spec so everyone
can be the same.

Yes it is.

> I imagine the calculation could get quite complicated. Yes I can use a newer version.
I'm not very familiar with software life cycle, will I need to wait for the RC for a fix?
If so, any guesses as to when that might be?

No, you don't need to wait for the RC. Some hours after the enhancements have been put in
there will be a newer 2.0.0-SNAPSHOT available.

> 
> Have a great weekend and thanks for the help!

You're welcome. Enjoy your weekend.

BR
Maruan
> 
> Jarrod
> --------------------------------------------
> On Fri, 7/10/15, Maruan Sahyoun <sahyoun@fileaffairs.de> wrote:
> 
> Subject: Re: Font AutoSize Issue
> To: users@pdfbox.apache.org
> Date: Friday, July 10, 2015, 3:55 PM
> 
> Hi,
> 
>> Am 10.07.2015 um 16:06 schrieb jarrod
> <xhozst@yahoo.com.INVALID>:
>> 
>> Evan,
>> 
>> I tested doing the
> same thing but decided it wasn't a very good solution in
> my case. There are a lot of fields to modify over multiple
> pages across numerous pdf's that are updated annually.
> Additionally, in my case the length of text can be fairly
> dynamic and fixing a font could be problematic for users
> doing manual data entry/correction. Thanks for your added
> input. Hopefully Mr Sahyoun has a solution for us.
> 
> I had a quick look. The issue
> is not that the autosizing doesn't work. It's the
> difference in calculating the available field size.
> Unfortunately, as this is not documented in the PDF spec one
> has to compare the content generated by Adobe and handle it
> from there. (e.g. Adobe adds padding to the fields bounding
> box but only to a certain limit, there are some edge cases
> ….)  Anyway, I think there will can achieve a result
> which is closer to what Adobe achieves using the data file
> and templates provided.
> 
> Do
> you have to stay on 1.8.x or would you be able to work with
> the 2.0.0-SNAPSHOT version? We are also planning to have an
> RC out soon.
> 
> As I'm on
> travel it will be start of next week until I can handle
> it.
> 
> BR
> Maruan
> 
> 
>> 
>> Thanks,
>> 
>> Jarrod
>> 
> --------------------------------------------
>> On Fri, 7/10/15, Evan Williams <evan.williams@zapprx.com>
> wrote:
>> 
>> Subject:
> Re: Font AutoSize Issue
>> To: users@pdfbox.apache.org
>> Date: Friday, July 10, 2015, 8:35 AM
>> 
>> I actually have seen
> the exact same
>> behavior in 1.8.9.
>> 
>> I dealt with it by
> just fixing the forms in Acrobat so that
>> the fonts have
>> a
> fixed size, because I did not have the time or the energy
>> to deal with
>> it. But
> autosized fonts definitely did not work for me when
>> filling out
>> forms in
> 1.8.9.
>> 
>> If it
> would be helpful and Jarrod does not have a good
>> example document I
>> 
> would be happy to publish one of mine.
>> 
> 
>> Thanks.
>> 
>> On Fri, Jul 10, 2015 at 4:19 AM, Maruan
> Sahyoun <sahyoun@fileaffairs.de>
>> wrote:
>> 
>>> Hi,
>>> 
>>> 
>>>> Am
> 10.07.2015 um 00:32 schrieb jarrod <xhozst@yahoo.com.INVALID>:
>>>> 
>>>> 
> I'm evaluating pdfbox for filling in form fields
>> from a template pdf
>>> file.
>>>> 
>>>> From what I can tell, pdfbox does
> not support
>> autosize font. While it
>>> will retain the font size 0 setting,
> the text that is
>> placed into the
>>> fields is not autosized (until you
> alter the value
>> manually).
>>>> 
>>>> 
> Option A:
>>>> Is there some kind of
> command to execute before
>> saving the
> pdf to force
>>> it to autosize?
>>>> 
>>>> 
> Option B:
>>>> Do some math and
> calculate a new font size. I've
>> 
> done this (see code
>>> below) but you
> obviously lose the ability to autosize
>> 
> if the user ends up
>>> modifying a
> value.
>>>> Is there a way to do
> this math and set the initial
>> display
> font size but
>>> leave the DA alone
> with autosize set?
>>>> I'm
> guessing this would be done by setting some
>> other COSName String
>>> similar to setting the COSName.DA.
> However, I can't
>> find much
> information
>>> on these.
>>> 
>>> 
>>> which version of PDFBox are you using?
> Do you have a
>> sample empty PDF and
>>> filled out one together with some code
> how you do the
>> form filling?
>>> 
>>> Both 1.8.9
> and 2.0.0-SNAPSHOT should support
>> 
> autosizing.
>>> 
>>> BR
>>> Maruan
>>> 
>>>> 
>>>> Any help is appreciated. Code is
> below;
>>>> 
>>>> //item.field_value is the value
> I'm sticking into
>> the form field
>>>> 
>>>> if
> (field instanceof PDTextbox)
>>>> 
> {
>>>>         int len =
>> item.field_value.length();
>>>>         if (len>2)
>>>>         {
>>>>             
>>     COSDictionary dict =
>> field.getDictionary();
>>>>             
>>     COSString defaultAppearance =
> (COSString)
>>> 
> dict.getDictionaryObject(COSName.DA);
>>>>             
>>     if (defaultAppearance != null)
>>>>             
>>     {
>>>>    
>           
>>           //split
> the DA to
>> grab the font size
>>>>               
>>           String[] da =
>>> 
> defaultAppearance.getString().split(" ");
>>>>               
>>           List<String>
>> da2 = new ArrayList<String>();
>>>> 
>>>>    
>           
>>           //loop
> through and
>> remove any empty strings
>>>>               
>>           // because for some
>> reason when the font size is 0
>>> there is an empty extra string in the
> way
>>>>               
>>           for(int x=0;
>> x<da.length; x++)
>>>>               
>>           {
>>>>               
>>               
>>     if (da[x].length()!=0)
>>>>               
>>                 
>>           da2.add(da[x]);
>>>>               
>>           }
>>>>               
>>           //Move back to a
>> String[] (I'm new to java)
>>>>               
>>           da =
>> 
> da2.toArray(da);
>>>> 
>>>>               
>>           if (da.length >=
>> 2) //only process if there are at
>>> least two characters
>>>>               
>>           {
>>>>               
>>               
>>     if (da[1].equals("0")) //If
> font size is
>>> actually autosized
>>>>               
>>               
>>     {
>>>>    
>           
>>                
> 
>>           COSArray
>> fieldAreaArray =
>>> 
> (COSArray) dict.getDictionaryObject(COSName.RECT);
>>>>               
>>                 
>>           PDRectangle rect =
>> new
>>> 
> PDRectangle(fieldAreaArray);
>>>>  
>             
>>              
>   
>>           float width =
>> rect.getWidth();
>>>> 
>>>>    
>           
>>                
> 
>>           int size =
>> (int)(width / len *
>>> 1.92); //doing stupid math to estimate
> new font size
>>>> 
>>>>               
>>                 
>>           if (size > 12)
>>>>               
>>                 
>>               
>>     size = 12;
>>>>               
>>                 
>>           else if (size <
>> 8)
>>>>        
>       
>>                 
>>               
>>     size = 8;
>>>> 
>>>>    
>           
>>                
> 
>>           String customSize =
>> "/Helv " +
>>> size + " Tf 0 g";
>>>> 
>>>>    
>           
>>                
> 
>>       
>>    
> dict.setString(COSName.DA,
>>> 
> customSize); //Set the new font size here
>>>>               
>>                 
>>           field = new
>> PDTextbox(acroForm,
>>> dict); //Create as a new field (as
> seen in other
>> threads)
>>>>               
>>               
>>     }
>>>>    
>           
>>           }
>>>>             
>>     }
>>>>    
>     }
>>>> }
>>>> field.setValue(item.field_value);
> //Set the field
>> value
>>>> 
>>>> 
> Jarrod
>>>> 
>>>> 
>> 
> ---------------------------------------------------------------------
>>>> 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
>>> 
>>> 
>> 
>> 
>> -- 
>> *Evan
> Williams*
>> Sr. Software Engineer
>> evan.williams@zapprx.com
>> 
>> *www.ZappRx.com
> <http://www.zapprx.com/>*
>> 
> 
>> 
>> 
> ---------------------------------------------------------------------
>> 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


Mime
View raw message