Jump to content

Trimming Text based on character count


Recommended Posts

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



Link to comment
Share on other sites

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.useTags = false;

var tmWidth = tm.textWidth;


return (tmWidth < frameWidth*7200) ? str : str.replace("@unecessarilylongdomain.com", "<br>@unecessarilylongdomain.com");

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...