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
  #21  
Old August 15th, 2016, 06:29 PM
VernF88 VernF88 is offline
Junior Community Member
 
Join Date: Aug 2016
Posts: 11
Default Re: Superscript tag inside ReplaceSubstring rule

Quote:
Originally Posted by Dan Korn View Post
Or you could just do this:
Code:
var frame = FindTextFrame('FullBody');
frame.content = frame.content.replace(/([\^\+]+)/g, '<superscript>$1</superscript>');
Also, why are you doing this?
Hello Dan, Currently we've been attempting this:
Code:
var chars = {
// Find:        Replace:
  '\\^':        '<superscript>^</superscript>',
  '\\+':        '<superscript>+</superscript>',
  '\\†':        '<superscript>†</superscript>',
  '\\‡':        '<superscript>‡</superscript>',     
  '<<first>>':   Field("First Name"),
  '<<last>>':    Field("Last Name"),
  '<<year>>':    Field("Year"),
  '<<make>>':    Field("Make"),
  '<<model>>':   Field("Model"),
  '<<model2>>':  Field("Model2"),
  '<<model3>>':  Field("Model3"),
  '<<V1>>':      Field("V1"),
  '<<V2>>':      Field("V2"),
  '<<V3>>':      Rule("V3R"),
  '<<V4>>':      Rule("V4R"),
  '<<V5>>':      Field("V5"),
  '<<more>>':    Rule("MoreR"),
  '<<actual>>':  Rule("ActualR"),
  '<<winno>>':   Field("WinNo"),
}
var text = FindTextFrame('FullBody').content
  .replace(/<variable name="([^"]*)">/g, 
    function(s,p) { 
      return FieldOrRule(p);
    });
for (var i in chars)
  text = text.replace(new RegExp(i, 'g'), chars[i]);
FindTextFrame('FullBody').content = text;
The rub is that the field's aren't filling because of the "<<>>" on each side of the space holder. Also the alt characters "†" and "‡" aren't being replaced with superscript.
Reply With Quote
  #22  
Old August 15th, 2016, 06:36 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Superscript tag inside ReplaceSubstring rule

Quote:
Originally Posted by Dan Korn View Post
Also, why are you doing this?
I converted the '<variable name="...">' tags to the actual strings that they're supposed to return before replacing the symbols in case a field or rule being returned in the text frame contains one of the symbols.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #23  
Old August 16th, 2016, 09:02 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Superscript tag inside ReplaceSubstring rule

Quote:
Originally Posted by VernF88 View Post
Okay for troubleshooting purposes I input 'first' instead of '<<first>>'. It then inserted the field, so it's the <<>> characters causing it to not work properly. Still not sure why the "†" and "‡" characters are not going to superscript though.
Maybe you could post the template and data that you're working with so that we could take a closer look?

My guess is that your template is converting those special characters to their HTML entities. Meaning the < is converted to &lt; and the > is converted to &gt;. So your find pattern is unable to come up with a match. I imagine the same is true for the daggers. If that assumption is true, this will probably work for you:
Code:
var chars = {
// Find:        Replace:
  '\\^':        '<superscript>^</superscript>',
  '\\+':        '<superscript>+</superscript>',
  '&dagger;':   '<superscript>†</superscript>',
  '&Dagger;':   '<superscript>‡</superscript>',     
  '<<first>>':   Field("First Name"),
  '<<last>>':    Field("Last Name"),
  '<<year>>':    Field("Year"),
  '<<make>>':    Field("Make"),
  '<<model>>':   Field("Model"),
  '<<model2>>':  Field("Model2"),
  '<<model3>>':  Field("Model3"),
  '<<V1>>':      Field("V1"),
  '<<V2>>':      Field("V2"),
  '<<V3>>':      Rule("V3R"),
  '<<V4>>':      Rule("V4R"),
  '<<V5>>':      Field("V5"),
  '<<more>>':    Rule("MoreR"),
  '<<actual>>':  Rule("ActualR"),
  '<<winno>>':   Field("WinNo"),
}
var text = FindTextFrame('FullBody').content
  .replace(/<variable name="([^"]*)">/g, 
    function(s,p) { 
      return FieldOrRule(p);
    })
  .replace(/&([lg])t;/g, 
    function(s,p) { 
      return p == 'l' ? '<' : '>';
    });

for (var i in chars)
  text = text.replace(new RegExp(i, 'g'), chars[i]);

FindTextFrame('FullBody').content = text;
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #24  
Old August 16th, 2016, 12:42 PM
VernF88 VernF88 is offline
Junior Community Member
 
Join Date: Aug 2016
Posts: 11
Smile Re: Superscript tag inside ReplaceSubstring rule

That works great! Thank you again for all your help!!!
Reply With Quote
  #25  
Old August 16th, 2016, 01:03 PM
VernF88 VernF88 is offline
Junior Community Member
 
Join Date: Aug 2016
Posts: 11
Default Re: Superscript tag inside ReplaceSubstring rule

The only other thing I'm struggling on with this is trying to get something like this to work:
Code:
  '<<actual>>++':  Rule("ActualR1"),
  '<<actual>>+':  Rule("ActualR2"),
  '<<actual>>&dagger;':  Rule("ActualR3"),
  '<<actual>>&Dagger;':  Rule("ActualR4"),
The reason being is the "actual" field in the letter is 36 point, so the superscript doesn't go up high enough. I made 4 rules applying each occurrence of the character options at the appropriate superscript height. It won't recognize this as text within the frame though. Thank You!
Reply With Quote
  #26  
Old August 16th, 2016, 01:39 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Superscript tag inside ReplaceSubstring rule

Quote:
Originally Posted by VernF88 View Post
The only other thing I'm struggling on with this is trying to get something like this to work:
Code:
  '<<actual>>++':  Rule("ActualR1"),
  '<<actual>>+':  Rule("ActualR2"),
  '<<actual>>&dagger;':  Rule("ActualR3"),
  '<<actual>>&Dagger;':  Rule("ActualR4"),
It's kind of difficult to say what's going on from just those 4 lines of code. I will remind you, though:
Quote:
Originally Posted by Step View Post
Keep in mind that both plus signs and carets have special meanings in regular expressions so they must be escaped.
Quote:
Originally Posted by VernF88 View Post
The reason being is the "actual" field in the letter is 36 point, so the superscript doesn't go up high enough. I made 4 rules applying each occurrence of the character options at the appropriate superscript height. It won't recognize this as text within the frame though. Thank You!
Again, I'm not really sure what you're saying. You can adjust the size and offset of the superscripting globally by adjusting your "Paragraph" settings.

But after creating 4 rules and a complicated regexp, wouldn't it be worth asking yourself "is this really any easier than inserting the placeholders with the fields from the text editor?"
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #27  
Old August 16th, 2016, 02:15 PM
VernF88 VernF88 is offline
Junior Community Member
 
Join Date: Aug 2016
Posts: 11
Default Re: Superscript tag inside ReplaceSubstring rule

Quote:
Originally Posted by step View Post
It's kind of difficult to say what's going on from just those 4 lines of code. I will remind you, though:


Again, I'm not really sure what you're saying. You can adjust the size and offset of the superscripting globally by adjusting your "Paragraph" settings.

But after creating 4 rules and a complicated regexp, wouldn't it be worth asking yourself "is this really any easier than inserting the placeholders with the fields from the text editor?"
I uploaded an image for my meaning. Next to the large "$13,555" are the superscript characters I'm wanting to correct with the rule. As you'll see in the next paragraph down next to the "$1,500 Bonus Cash" the "+" character is the correct height. So the global setting cannot be modified to fix the issue. The code I have in the rule's correct the height and insure they aren't bold:
Code:
return FormatNumber("$#,###", Field("Actual").replace(/[^\d\.-]/g,'')) + "<p br=false superoffset=175 superratio=30><span bold=false><superscript>++</superscript></span bold=false><p br=false superoffset=58 superratio=50>"
That will produce the correct height "++". Literally whats in the text frame is "<<actual>>++" so I input:
Code:
var chars = {
// Find:              Replace:
  '\\^':        '<superscript>^</superscript>',
  '\\+':      '<superscript>+</superscript>',
  '&dagger;':   '<superscript>†</superscript>',
  '&Dagger;':   '<superscript>‡</superscript>',
  '<<first>>':   Field("First Name"),
  '<<last>>':    Field("Last Name"),
  '<<year>>':    Field("Year"),
  '<<make>>':    Field("Make"),
  '<<model>>':   Field("Model"),
  '<<model2>>':  Field("Model2"),
  '<<model3>>':  Field("Model3"),
  '<<V1>>':      Field("V1"),
  '<<V2>>':      Field("V2"),
  ' <<V3>>':      Rule("V3R"),
  ' <<V4>>':      Rule("V4R"),
  '<<V5>>':      Field("V5"),
  '<<v1>>':      Field("V1"),
  '<<v2>>':      Field("V2"),
  ' <<v3>>':      Rule("V3R"),
  ' <<v4>>':      Rule("V4R"),
  '<<v5>>':      Field("V5"),
  '<<more>>':    Rule("MoreR"),
  '<<actual>>\\++':  Rule("ActualR1"),
  '<<actual>>\\+':  Rule("ActualR2"),
  '<<actual>>&dagger;':  Rule("ActualR3"),
  '<<actual>>&Dagger;':  Rule("ActualR4"),
  '<<actual>>':  Rule("ActualR"),
  '<<winno>>':   Field("WinNo"),
}
var text = FindTextFrame('FullBody').content
  .replace(/<variable name="([^"]*)">/g, 
    function(s,p) { 
      return FieldOrRule(p);
    })
   .replace(/&([lg])t;/g, 
     function(s,p) { 
       return p == 'l' ? '<' : '>';
     });
for (var i in chars)
  text = text.replace(new RegExp(i, 'g'), chars[i]);
FindTextFrame('FullBody').content = text;
I realize I could highlight and replace the space holder but that's literally the last thing left in the letter that isn't automated. I appreciate all your help!

Last edited by VernF88; August 16th, 2016 at 02:18 PM..
Reply With Quote
  #28  
Old August 17th, 2016, 06:43 AM
VernF88 VernF88 is offline
Junior Community Member
 
Join Date: Aug 2016
Posts: 11
Default Re: Superscript tag inside ReplaceSubstring rule

Quote:
Originally Posted by VernF88 View Post
I uploaded an image for my meaning. Next to the large "$13,555" are the superscript characters I'm wanting to correct with the rule. As you'll see in the next paragraph down next to the "$1,500 Bonus Cash" the "+" character is the correct height. So the global setting cannot be modified to fix the issue. The code I have in the rule's correct the height and insure they aren't bold:
Code:
return FormatNumber("$#,###", Field("Actual").replace(/[^\d\.-]/g,'')) + "<p br=false superoffset=175 superratio=30><span bold=false><superscript>++</superscript></span bold=false><p br=false superoffset=58 superratio=50>"
That will produce the correct height "++". Literally whats in the text frame is "<<actual>>++" so I input:
Code:
var chars = {
// Find:              Replace:
  '\\^':        '<superscript>^</superscript>',
  '\\+':      '<superscript>+</superscript>',
  '&dagger;':   '<superscript>†</superscript>',
  '&Dagger;':   '<superscript>‡</superscript>',
  '<<first>>':   Field("First Name"),
  '<<last>>':    Field("Last Name"),
  '<<year>>':    Field("Year"),
  '<<make>>':    Field("Make"),
  '<<model>>':   Field("Model"),
  '<<model2>>':  Field("Model2"),
  '<<model3>>':  Field("Model3"),
  '<<V1>>':      Field("V1"),
  '<<V2>>':      Field("V2"),
  ' <<V3>>':      Rule("V3R"),
  ' <<V4>>':      Rule("V4R"),
  '<<V5>>':      Field("V5"),
  '<<v1>>':      Field("V1"),
  '<<v2>>':      Field("V2"),
  ' <<v3>>':      Rule("V3R"),
  ' <<v4>>':      Rule("V4R"),
  '<<v5>>':      Field("V5"),
  '<<more>>':    Rule("MoreR"),
  '<<actual>>\\++':  Rule("ActualR1"),
  '<<actual>>\\+':  Rule("ActualR2"),
  '<<actual>>&dagger;':  Rule("ActualR3"),
  '<<actual>>&Dagger;':  Rule("ActualR4"),
  '<<actual>>':  Rule("ActualR"),
  '<<winno>>':   Field("WinNo"),
}
var text = FindTextFrame('FullBody').content
  .replace(/<variable name="([^"]*)">/g, 
    function(s,p) { 
      return FieldOrRule(p);
    })
   .replace(/&([lg])t;/g, 
     function(s,p) { 
       return p == 'l' ? '<' : '>';
     });
for (var i in chars)
  text = text.replace(new RegExp(i, 'g'), chars[i]);
FindTextFrame('FullBody').content = text;
I realize I could highlight and replace the space holder but that's literally the last thing left in the letter that isn't automated. I appreciate all your help!
Sorry my photo was too large I just now noticed I'm uploading a resized photo.
Attached Images
File Type: jpg 96dpi.jpg (194.1 KB, 5 views)
Reply With Quote
Old August 23rd, 2016, 05:45 PM
VernF88
This message has been deleted by VernF88.
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 09:21 AM.


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