IceisforHockey Posted January 14 Posted January 14 JS is not my thing.... that being said need some help. I am trying to change the first letters of a salutation line in an address to a different font and font size. It is made up of fields: Title, First Name, Last Name and Other eg. Mr. and Mrs. John Doe and Family - I would like all First letters which are capital (not the ands) to switch to a different font and a bigger size. "M", "M", "J", "D" "F" Thanks for any help in advance Quote
Dan Korn Posted January 15 Posted January 15 Something like this: var s = "Mr. and Mrs. John Doe and Family"; return TaggedFromRaw(s).replace(/[A-Z]/g, '<span font="Courier New" pointsize=20>$&</span>'); Quote
IceisforHockey Posted January 15 Author Posted January 15 Thanks Dan!! Quick follow up... Is the original font (for all the lowercase characters) set in the text editor in the PDF? meaning I want all characters to be arial except for the capital letters to be in Helvetica. Thanks again Quote
Dan Korn Posted January 15 Posted January 15 7 minutes ago, IceisforHockey said: Is the original font (for all the lowercase characters) set in the text editor in the PDF? meaning I want all characters to be arial except for the capital letters to be in Helvetica. Yes, any character that's not modified by the rule to be in a particular font and size will be in whatever font the text is in nominally, i.e. whatever font and point size was set for the rule in the Text Editor. If you want to specify both fonts in the rule instead, then you can just put another font tag in front of everything, like so: var s = "Mr. and Mrs. John Doe and Family"; return '<f name="Arial">' + TaggedFromRaw(s).replace(/[A-Z]/g, '<span font="Helvetica" pointsize=20>$&</span>'); If you want the point size of the capital letters to be a multiple of the original point size, rather than hard-coded to something like 20 points, then you can do this: var s = "Mr. and Mrs. John Doe and Family"; return '<f name="Arial">' + TaggedFromRaw(s).replace(/[A-Z]/g, '<span font="Helvetica"><magnify factor=200>$&</magnify></span>'); Quote
IceisforHockey Posted January 21 Author Posted January 21 Hi Dan Been working on my little project... ran into something I cant figure out. This is what I got so far var s = Field("Name") + Field("Title") + Field("Company"); return '<span font="Helvetica 55" pointsize=22>' + TaggedFromRaw(s).replace(/[A-Z]/g, '<span font="Helvetica 95" pointsize=28>$&</span>'); It outputs as expected... so I added + " " + between each field to give me spaces: var s = Field("Name") + " " + Field("Title") + " " + Field("Company"); return '<span font="Helvetica 55" pointsize=22>' + TaggedFromRaw(s).replace(/[A-Z]/g, '<span font="Helvetica 95" pointsize=28>$&</span>'); The problem I have is if the record doesn't have a Title I get an extra space. This is unlike if I do this straight in the text editor where I check ignore if empty the space is not put in. Is there a way to build that into the rule? Also if I wanted to put Company on the next line is there a way to put in the <br>? thanks Quote
Dan Korn Posted January 22 Posted January 22 Sure, you can remove empty items and just put spaces between what's left. There are a lot of ways you can do this, probably the most succinct is: var s = [Field("Name"), Field("Title"), Field("Company")].filter(String).join(' '); If you want the company on another line, sure, you can conditionally put out either a <p> or <br> tag if the Company field is not empty, though you have to make sure that you don't put the tag in before calling TaggedFromRaw. The best way to do that is to call the TaggedDataField function, something like this: var s = [TaggedDataField("Name"), TaggedDataField("Title")].filter(String).join(' '); if (Field("Company")) s += "<br>" + TaggedDataField("Company"); Or like this: var s = [[TaggedDataField("Name"), TaggedDataField("Title")].filter(String).join(' '), TaggedDataField("Company")].filter(String).join('<br>'); Quote
IceisforHockey Posted January 22 Author Posted January 22 I cant seem to get the break properly the break properly... var s = [[TaggedDataField("Name"), TaggedDataField("Title")].filter(String).join(' '), TaggedDataField("Company")].filter(String).join('<br>'); return '<span font="Helvetica 55" pointsize=22>' + TaggedFromRaw(s).replace(/[A-Z]/g, '<span font="Helvetica 95" pointsize=28>$&</span>'); This is the Result: Jon Doe President <br> Acme Dynamite Quote
Dan Korn Posted January 22 Posted January 22 Remove the TaggedFromRaw call from the last line, like so: var s = [[TaggedDataField("Name"), TaggedDataField("Title")].filter(String).join(' '), TaggedDataField("Company")].filter(String).join('<br>'); return '<span font="Helvetica 55" pointsize=22>' + s.replace(/[A-Z]/g, '<span font="Helvetica 95" pointsize=28>$&</span>'); Quote
IceisforHockey Posted January 22 Author Posted January 22 Sorry... I'm Baaack... I have a second variable text box in the PDF that displays another field named "Industry" It is in a different font Caslon Pro When I compose the document the first page composes perfectly and every other page the font changes to Arial. Is there something in this code that might be doing this? Thanks Quote
Dan Korn Posted January 23 Posted January 23 1 hour ago, IceisforHockey said: When I compose the document the first page composes perfectly and every other page the font changes to Arial. Is there something in this code that might be doing this? It's impossible to analyze without seeing the job. Can you collect it up, with a minimal data file, and post it here? Quote
IceisforHockey Posted January 31 Author Posted January 31 On 1/22/2024 at 5:14 PM, Dan Korn said: var s = [[TaggedDataField("Name"), TaggedDataField("Title")].filter(String).join(' '), TaggedDataField("Company")].filter(String).join('<br>'); return '<span font="Helvetica 55" pointsize=22>' + s.replace(/[A-Z]/g, '<span font="Helvetica 95" pointsize=28>$&</span>'); Is there a way to get this to copyfit if needed? Right now the OnCopyFit rule doesnt seem to work on the above rule? Thanks Quote
Dan Korn Posted January 31 Posted January 31 19 hours ago, IceisforHockey said: Is there a way to get this to copyfit if needed? Right now the OnCopyFit rule doesnt seem to work on the above rule? In what way does it not work? What result are you getting, and exactly how is it different than the result you're expecting? Are you trying to shrink the text to fit into a smaller box, or expand it to a larger box, or both? You probably need to change the settings in the OnCopyfit rule. By default, the first line is this: if (!Copyfit(new MagnifyAttributes("text", 25, 400, 6, 72))) Where the parameters to the MagnifyAttributes constructor function, which are documented in the Rules Guide, and on the Objects tab of the Building Blocks dialog, are: new MagnifyAttributes(type, factormin, factormax, min, max) So by default, the point size is capped to a minimum of 25 percent of the original size, or 6 points, whichever is hit first, and a maximum of 400 percent of the original size, or 72 points, whichever it hits first. You probably need to tweak those settings for the particular text and frame you're trying to fit. If you need to have different settings for different text frames, there's a section in the Rules Guide that explains how to do that, based on the frame name. Or, if you're using FP 13 or later, you can adjust the copyfit settings for each frame independently in the Overflow Options dialog, and you don't have to mess with the JavaScript at all. Quote
IceisforHockey Posted February 4 Author Posted February 4 sorry for being so vague.... What is not working is that instead of the the text being on one (albeit in a smaller font) I am getting a text break. ie Mr. John D oe Acme Hardware what I expected was that oncopyfit would kick in and I would get in a smaller font Mr. John Doe Acme Hardware I do have "do not break on copyfit" checked thanks Quote
Dan Korn Posted February 5 Posted February 5 Just checking, you did go into the Frame Properties for that frame and click Overflow, then clicked the "Adjust text to fit" button, right? Quote
Dan Korn Posted February 6 Posted February 6 Okay, well, as I noted before, we've reached the limit of what I can diagnose by looking at your job through the keyhole of just the rule. I would need to see the entire job in order to figure out what's going on. But I think you should be able to tweak those settings in the OnCopyfit rule, as I also mentioned earlier. Have you tried that? Quote
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.