Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Formatting Text

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 30th, 2021, 08:20 AM
Dmiller35 Dmiller35 is offline
Junior Community Member
 
Join Date: Jun 2020
Location: South Carolina, USA
Posts: 12
Default Trimming Text based on character count

I have a document that has a limited amount of space and one of the fields is an email address. I can do a copyfit, but in order to keep everything on one line, the font has to go from 9pt down to 5 on some records. (The client's domain name is stupidly long).

Is there a way to splt the email at the "@" so that when it's longer that 32 characters, it drops the "@unecessarilylongdomain.com" down to a second line?
Every record has the same domain name so is there a way to trim the right 25 characters?

This way jonathan.doe@unecessarilylongdomain.com would become
jonathan.doe
@unecessarilylongdomain.com
Reply With Quote
  #2  
Old December 30th, 2021, 02:14 PM
Susan Susan is offline
Regular Contributor
 
Join Date: Oct 2008
Location: Maitland, FL
Posts: 63
Default Re: Trimming Text based on character count

I've used this rule which uses the width of your text box and will break the email address if it doesn't fit.


// Use TextMeasure to get the length of each email
var tm = new FusionProTextMeasure;
var frameWidth = 2.5; // set width of the text box (in inches)
tm.pointSize = "10 pt"; // set the type size
tm.font = "Calibri"; // set your typeface
var str = Field("email address"); // set the field to use
tm.CalculateTextExtent(str);
tm.useTags = false;
var tmWidth = tm.textWidth;

return (tmWidth < frameWidth*7200) ? str : str.replace("@unecessarilylongdomain.com", "<br>@unecessarilylongdomain.com");
__________________
FusionPro Creator v10.1.11 / FusionPro Producer / FusionPro Expression 3.2.2 / Mac OSX 10.14.6 / Acrobat Pro DC
Reply With Quote
  #3  
Old December 31st, 2021, 05:15 AM
jwhittaker jwhittaker is offline
Senior Contributor
 
Join Date: Feb 2009
Location: San Diego
Posts: 168
Default Re: Trimming Text based on character count

D Miller
You could try something like this? I know there is a more efficient way but this should still work.

if (Len(Field("Email")) >= 32)
{
var emailarray = Field("Email").split("@");
return emailarray[0] + '<p>' + "@" + emailarray[1];
}
else
return Field("Email");
__________________
FusionPro VDP Creator 10.0.26 | MacOS 10.13.4 | Acrobat DC
Reply With Quote
  #4  
Old January 6th, 2022, 07:27 AM
Dmiller35 Dmiller35 is offline
Junior Community Member
 
Join Date: Jun 2020
Location: South Carolina, USA
Posts: 12
Default Re: Trimming Text based on character count

Thanks Susan. That worked great.
__________________
FusionPro VDP Creator 12.1.0 | MacOS 10.14.6 | Acrobat DC
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:04 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.