Jump to content

Salutation Line Font and Size Change


Recommended Posts

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

Link to comment
Share on other sites

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>');
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>');

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>');
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 2 weeks later...
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

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