ReminderVDP Posted February 18, 2013 Share Posted February 18, 2013 I'm trying to see if there is a way to write a Javascript rule for this issue. We have variable letters for every customer that come in all different lengths. We'd like the people who only have one paragraph to expand in point size from 9.5 to 12 in the letter. In the User Guide it says that you have to check Expand to Fill in the text Overflow control to make this happen. However, that expands every letter to fill the space. Is there a way to expand the letters only with one paragraph? Quote Link to comment Share on other sites More sharing options...
ReminderVDP Posted February 18, 2013 Author Share Posted February 18, 2013 One thing I thought of is if a rule could be created based on the character limit in the letter. We currently allow 1800 characters. So, I'd say if there was a way to tell the letter to increase in point size for any letters under 1000 characters, that would be ideal and cover any short letters. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted February 18, 2013 Share Posted February 18, 2013 What exactly do you mean by "one paragraph?" In other words, what does the data look like? How are paragraphs delimited? Are there <p> tags embedded in the data, or <br> tags, or simply newline characters? I need to know exactly what's in the data in order to suggest something. Can you post a sample? If you want to do something based on the number of characters, that's pretty simple. Something like this: if (Len(Field("YourFieldName")) < 1000) return '<z newsize=12>' + Field("YourFieldName"); //else return Field("YourFieldName"); Quote Link to comment Share on other sites More sharing options...
esmith Posted February 18, 2013 Share Posted February 18, 2013 I've never had reliable results when dealing with rules based on character limits, but to answer your 2nd post, you could create tagged text in a rule like this: var letter = Field("LETTER-TEXT"); var result = (letter.length > 1000) ? '<z newsize="12">' : '<z newsize="9.5">'; result += letter; return result; Alternatively (and depending on how your data indicates paragraphs), you could test your letter value to see if the paragraph break is present. If it isn't, then you add in similar logic to increase the point size. As an example, if your data returns a double return between two paragraphs, you could do something like: var letter = Field("LETTER-TEXT"); var result = (letter.search(/\r\r/ == -1) ? '<z newsize="12">' : '<z newsize="9.5">'; result += letter; return result; Quote Link to comment Share on other sites More sharing options...
ReminderVDP Posted February 18, 2013 Author Share Posted February 18, 2013 The current rule is a lookup for a .txt file with the rule below. How would the character length check fit into this rule? // Return tagged text file with embeded resource var Var1 = "LetterFileName"; var Var2 = ".txt"; var Var3 = ""; var Var4 = "NoLetterAvailable.txt"; temp = ''; var_extension = ''; has_extension = ''; if (Var3 == "") Var3 = Var3; else { if (FusionPro.isMac) Var3 = Var3 + ":"; else Var3 = Var3 + "\\"; } for (i=0; i<Field(Var1).length; i++) { temp = Mid(Field(Var1), Field(Var1).length-i,1); var_extension = temp + var_extension; if(var_extension == ".txt") { has_extension = "true"; i=Field(Var1).length; } else has_extension = "false"; } if(has_extension == "true") LetterText = CreateResource(Var3 + Field(Var1), "Plain text file", true); else { if(Var2 == ".txt") { Pic = CreateResource(Var3 + Field(Var1) + ".jpeg", "graphic", true); if (Pic.exists) Pic = Pic; else Pic = CreateResource(Var3 + Field(Var1) + ".jpg", "graphic", true); } if(Var2 == ".tif") { Pic = CreateResource(Var3 + Field(Var1) + ".tif", "graphic", true); if (Pic.exists) Pic = Pic; else Pic = CreateResource(Var3 + Field(Var1) + ".tiff", "graphic", true); } if(Var2 == ".png" || Var2 == ".pdf" || Var2 == ".eps" || Var2 == ".gif") { Pic = CreateResource(Var3 + Field(Var1) + Var2, "graphic", true); } } if (LetterText.exists) { return LetterText; } else { return CreateResource(Var3 + Var4, "graphic", true); } Quote Link to comment Share on other sites More sharing options...
ReminderVDP Posted February 19, 2013 Author Share Posted February 19, 2013 Or would it go in the OnRecordStart Rule field? Quote Link to comment Share on other sites More sharing options...
ReminderVDP Posted February 27, 2013 Author Share Posted February 27, 2013 I've tried these in the rule and it always goes to point size 12, even if the letter is way below 500 characters. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted February 27, 2013 Share Posted February 27, 2013 (edited) Well, like I said, it's hard to analyze your rule in a vacuum, without the rest of the job. At a minimum, I'd have to see what the data file looks like. Also, there's a lot of completely unnecessary code in that rule. For instance, all the code in blocks gated with if(Var2 == ".tif") and the like is never going to be hit, since you've hard-coded Var2 = ".txt"; right at the top. So I would clean up the code first before trying to add more logic to it. But I don't know for sure what all can be cleaned up without having some data, so that I can try running the rule myself. And, if I could see the whole job and the data, I (or someone else) might be able to figure out a better approach, which doesn't rely on some fuzzy logic to guess how much space something might take up based purely on the number of characters, which, as Eric rightly points out, isn't very reliable. Now, having said all of that, I'm not sure that you need to try to fit the logic to change the point size into the existing rule at all. You can just take the result of the first rule and use that in a new rule. For instance, if the name of the existing rule that you posted is "Letter Rule", then you can create a second rule to call that, like so: var MyLetterText = Rule("Letter Rule"); if (Len(MyLetterText) < 1000) return '<z newsize=12>' + MyLetterText; //else return MyLetterText;Then you can call out the name of this rule in your text frame instead of the name of the first rule. Edited February 27, 2013 by Dan Korn simpler function Quote Link to comment Share on other sites More sharing options...
ReminderVDP Posted March 4, 2013 Author Share Posted March 4, 2013 That works a lot better Dan than trying to fit it in the rule. It does make the text larger but instead of calling in the actual letter text from the rule "Letter Rule," it place the name of the letter at 12 points. Any insight to why "Letter Rule" looks up the text file and displays it in the layout and this rule just enlarges the name of the text file instead of actually bringing in the text? I've attached screen shots of the two. I'm using your code but changed the names to match my rules. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted March 4, 2013 Share Posted March 4, 2013 That works a lot better Dan than trying to fit it in the rule. It does make the text larger but instead of calling in the actual letter text from the rule "Letter Rule," it place the name of the letter at 12 points. Any insight to why "Letter Rule" looks up the text file and displays it in the layout and this rule just enlarges the name of the text file instead of actually bringing in the text? I've attached screen shots of the two. I'm using your code but changed the names to match my rules. Either change the line near the end of the first rule to call the "content" property of the resource, like so: return LetterText.content;Or change the first line of the second rule to access the property, like so: var MyLetterText = Rule("Letter Rule").content; Quote Link to comment Share on other sites More sharing options...
ReminderVDP Posted March 4, 2013 Author Share Posted March 4, 2013 Thanks Dan, that did it. It seems to work after the Rule in the variable line but not in the return line. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.