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


Thread Tools Search this Thread Display Modes
Old February 5th, 2016, 06:19 AM
johper johper is offline
Forum n00b
Join Date: Feb 2016
Posts: 2
Default Removing separator


I'm creating a business card template and I have a problem getting rid of of a separator at the end of a text line when there's a line break. The customer can select different brands in a html checkbox list and automatically the selected brands align with comma between them. I have managed to replace the comma with dash and no break space and allow only linebreak after the dash. But I also want to remove the dash at the end of the line in case there is a line break.

Image: http://s30.postimg.org/ajtqvu94h/procar.jpg

This is code I´m using so far:

var mystring = (Field("Extra line"))

function NoBreak(s)
return s.replace(/ /g, " ");
mystring2 = NoBreak(mystring);

var newchar = ' - '
mystring3 = mystring2.split(',').join(newchar);

return mystring3;

Any help would be appreciated.
Attached Images
File Type: jpg procar.jpg (51.9 KB, 5 views)
Reply With Quote
Old February 5th, 2016, 10:28 AM
step's Avatar
step step is offline
Senior Contributor
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Removing separator

I think the only way to do this is to use TextMeasure. You'd have to check the width of the string as it relates to the width of the text frame for each item that you add. If the item causes the string to be greater than the width of the text frame, add it with a page break; otherwise, add it with a dash:
// Make sure that "Treat returned strings as tagged text" and 
// "Re-evaluate this rule for every text flow" is checked. 
// Make sure that you have given the frame a name

// Width of the frame. Set to 3 inches when validating the rule.
var frameWidth = !FusionPro.inValidation ? GetSettableTextWidth(FindTextFrame(FusionPro.Composition.CurrentFlow.name)) : 21600;
var str = Field('Extra Line').split(',');                // Create an array of cars by splitting on a comma (,)
var result = '';                                         // String to hold the result
while (str.length) {
    var cat = [result,Trim(str.shift())].filter(String); // Array to hold concatenated string
    var glue = ' - ';                                    // Join the new car to the result string with a dash (-) by default
    if (getTextWidth(cat.join(glue)) > frameWidth)       // If joining with a dash exceeds the width of the frame, 
        glue = '<br>';                                   // join with a line break instead
    result = cat.join(glue);                             // Set the result to the concatenated string
return result;

// Helper function that determines the width of a string ('input')
function getTextWidth(input){
    var tm = new FusionProTextMeasure;
    tm.pointSize = "12pt";  // Font size of the string we're returning
    tm.font = "Helvetica";  // Font face of the string we're returning
    return tm.textWidth;
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

Reply With Quote
Old February 8th, 2016, 02:35 AM
johper johper is offline
Forum n00b
Join Date: Feb 2016
Posts: 2
Default Re: Removing separator

Thank you very much!
Works perfectly!
Reply With Quote

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 11:15 AM.

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