This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes Calculate text length Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Calculate text length" Watch "Calculate text length" New topic
Author

Calculate text length

Nicholas Turner
Ranch Hand

Joined: May 24, 2003
Posts: 126
I need to in jsp or a servlet calculate the width of a string if i know the font size,type and string?
how would I do this?
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
I don't think that there is anyway to do this within a servlet as the rendering of the HTML is performed by the client's browser.
The width of a field or portion of text is determined by all sorts of variables such as the fonts that are actually installed on the clients PC, the preferred text size set by the user etc... This information is not passed to the servlet at all therefore the width cannot be determined.
Sorry I can't provide a solution


Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calculate text length