Jump to content

Line Break at a Hyphen with Rules


ReminderVDP

Recommended Posts

I am trying to break a line of text at a hyphen in someone's title with a rule and can't figure out how. Currently, the title will break like this based on the copyfit rule.

 

Director - Wealth

Management

 

I'd like it to break after the hyphen so it reads like this:

 

Director -

Wealth Management

 

Any ideas?

Link to comment
Share on other sites

  • 1 year later...
Create a new rule like this:

 

return Field("Title").replace("- ", "-<br>");

 

Turn on treat strings as tagged text.

 

I need to use this rule to replace ALL semicolons in a field with line breaks, but what I get is literally <br> inserted between the text in place of the semicolon, and it only does it the first time and ignores all other occurrences. How can I replace all instances of a semicolon with line breaks in a variable field.?

Link to comment
Share on other sites

I need to use this rule to replace ALL semicolons in a field with line breaks, but what I get is literally <br> inserted between the text in place of the semicolon, and it only does it the first time and ignores all other occurrences. How can I replace all instances of a semicolon with line breaks in a variable field.?

 

You can try:

return Field("MyFieldName").replace(/;/[color="Red"]g[/color], "<br>");

 

The red g = global match.

 

More info on the replace() method can be found here.

Link to comment
Share on other sites

Check the "Treat returned strings as tagged text" box in the Rule Editor.

 

Also, to avoid problems with certain markup characters which may already be present in the data, you probably also want to change the rule to this:

return TaggedTextFromRaw(Field("MyFieldName")).replace(/;/g, "<br>");

Or, if you might be submitting this job to a web-to-print system such as MarcomCentral, which may be generated a tagged markup data file for the job, this is the ideal solution:

return TaggedDataField("MyFieldName").replace(/;/g, "<br>");

Link to comment
Share on other sites

  • 3 months later...
Or, if you might be submitting this job to a web-to-print system such as MarcomCentral, which may be generated a tagged markup data file for the job, this is the ideal solution:

return TaggedDataField("MyFieldName").replace(/;/g, "<br>");

 

I've tried using this code and I've gotten it to validate and work when I'm using FusionPro in Adobe Acrobat, but when I upload the template to MacromCentral and try to preview the rule in effect, it doesn't recognize it and only prints a semicolon instead of the line break. I've even downloaded the template from the website and reopened it up in Acrobat to find that the rule is still there and working. It's only when I attempt to put it online that it doesn't.

Link to comment
Share on other sites

I've tried using this code and I've gotten it to validate and work when I'm using FusionPro in Adobe Acrobat, but when I upload the template to MacromCentral and try to preview the rule in effect, it doesn't recognize it and only prints a semicolon instead of the line break. I've even downloaded the template from the website and reopened it up in Acrobat to find that the rule is still there and working. It's only when I attempt to put it online that it doesn't.

Are you sure you're uploading the new .def file with the changes to the rule?

 

I would add some debugging to the rule, like so:

var originalText = TaggedDataField("MyFieldName");
var newText = originalText.replace(/;/g, "<br>");
Print('original text "' + originalText + '", changed to "' + newText + '"';
return newText;

And look in the composition log file to see what it says. In MarcomCentral, if you view the output PDF in your web browser, you can change the extension at the end of the URL from .pdf to .msg to see the log file.

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.

Guest
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...