Jump to content

Formatting Headache Redux


Recommended Posts

I have found a few mentions of this but in the threads/solutions I have seen, I can't figure out how to make it work for my case.

 

I have 4 lines that are left aligned and containing 2 different fonts as well as tabs. They all need to left align but that alignment needs to start with the longest line (always the last line) ending at .25 from the right side. They also suppress if empty.

 

D «Direct Line»

C «Cell Phone»

E «Email Address»

L «Linkedin URL»

 

Help?

Link to comment
Share on other sites

Something like this:

var fields = 
[
   ["D", "Direct Line"],
   ["C", "Cell Phone"],
   ["E", "Email Address"],
   ["L", "Linkedin URL"],
];

var frameWidth = 3 * 7200; // for rule validation, 3 inches
var frame = FusionPro.Composition.CurrentFlow.GetFrame();
if (frame.GetSettableTextWidth)
   frameWidth = frame.GetSettableTextWidth();

var tm = new FusionProTextMeasure;
tm.font = "Arial"; // change to your font
tm.pointSize = 20 * 100; // change to your point size

var widest = 0;
var r = [];
for (var i in fields)
{
   var val = TaggedDataField(fields[i][1]);
   if (!val)
       continue;

   var text = fields[i][0] + " " + val;
   tm.CalculateTextExtent(text);
   widest = Math.max(widest, tm.textWidth);
   r.push(text);
}

var indent = frameWidth - widest - (0.25 * 7200); // .25 inch right margin
return '<p br=false findent=' + indent + ' lindent=' + indent + '>\n' + r.join('<br>\n');

A few notes:

  • You need to check both the "Re-evaluate this rule for every text flow" and "Treat returned strings as tagged text" boxes.
  • You need to hard-code the font and point size in the rule. (It's set to 20 point Arial in my code.)
  • I didn't assume which line would be the longest, so I measure them all.
  • This could also be done with tab stops instead of indents.
  • If a line of text is wider than the frame, then you'll get negative indent values, and nothing good will happen. I'll leave handling that condition as an exercise for the reader.

Link to comment
Share on other sites

Thank you Dan. I appreciate the help. I am getting an error saying FusionPro.Composition.CurrentFlow.GetFrame isn't a function.

 

Assuming that can be sorted, I have run into additional complications where this approach may not be the best. I need to be able to suppress if empty any of these fields/lines as well as have the label letter be a different color than the field text. For these reasons, I thought maybe simply having a few pages in my PDF allowing for different lengths of the Linkedin URL field would work and having FusionPro evaluate the length of that field to determine which page to use. That way I could just use the regular suppress if empty and formatting. Does that make sense?

 

If so, I am at a loss for how to code for that. I have researched how to reference pages in a PDF in FP but nothing I've tried seems to work. It seems like it should be fairly simple to say if field("Linkedin URL") is less than 24 characters, use page 1 for the front and page 3 for the back. If it's less than 28 characters, use page 2 for the front and page 3 for the back. Hope I'm not either over simplifying or over complicating.

 

Obviously a way to both have the label letter be one color, the field text be another, suppress the line if empty AND adjust the indent for the longest line would be the most complete solution but I fear I would be out of my depth with that.

Edited by designerspressinc
Link to comment
Share on other sites

Thank you Dan. I appreciate the help. I am getting an error saying FusionPro.Composition.CurrentFlow.GetFrame isn't a function.

Sorry, that's a function in FusionPro 10.1.

 

Your original post didn't specify the version of FusionPro you're running. That's why I recommend putting that info in your signature, so that it's included with every post.

 

Also, some other context about what you're doing, such as a sample template, would help me to provide more specific answers. At the very least, having some sample data would make things easier for me, as without your data, I either need to dummy some up, or write the rule for a different job's data, then change it before posting.

 

Anyway, in FusionPro 10.0, you can change line 10 in my rule to this:

var frame = FindTextFrame(FusionPro.Composition.CurrentFlow.name || "Info");

And make sure you name your frame "Info", or whatever you put for the name on that line.

Assuming that can be sorted, I have run into additional complications where this approach may not be the best. I need to be able to suppress if empty any of these fields/lines

My code does that. On line 24, if the value of the field is empty, that whole line is skipped, i.e. not added to the output.

as well as have the label letter be a different color than the field text.

So here is where I will make another suggestion regarding posting a question like this, which is to please specify all the requirements up front.

 

Anyway, just change line 26 to this:

    var text = '<span color="Red">' + fields[i][0] + '</span> ' + val;

With whatever color name you want.

For these reasons, I thought maybe simply having a few pages in my PDF allowing for different lengths of the Linkedin URL field would work and having FusionPro evaluate the length of that field to determine which page to use. That way I could just use the regular suppress if empty and formatting. Does that make sense?

I wouldn't do that. It's a lot more more work if you have to make any other changes, since you would have to make them on multiple pages. The job will be more complicated, harder to maintain, and probably slower to compose.

If so, I am at a loss for how to code for that. I have researched how to reference pages in a PDF in FP but nothing I've tried seems to work. It seems like it should be fairly simple to say if field("Linkedin URL") is less than 24 characters, use page 1 for the front and page 3 for the back. If it's less than 28 characters, use page 2 for the front and page 3 for the back. Hope I'm not either over simplifying or over complicating.

I think that's way more complicated than just having one rule that does the measurement, and one text frame to hold the results. Also, you don't really want to use the number of characters to "measure" text, since, unless you're using a fixed-width font (and even then it's tricky), different characters have different widths. That's why we have the Text Measurement functionality in FusionPro.

Obviously a way to both have the label letter be one color, the field text be another, suppress the line if empty AND adjust the indent for the longest line would be the most complete solution but I fear I would be out of my depth with that.

I think, with my changes listed above, this meets all of those requirements, and will work in FusionPro 10.0. Here it is with those changes:

var fields = 
[
   ["D", "Direct Line"],
   ["C", "Cell Phone"],
   ["E", "Email Address"],
   ["L", "Linkedin URL"],
];

var frameWidth = 3 * 7200; // for rule validation, 3 inches
var frame = FindTextFrame(FusionPro.Composition.CurrentFlow.name || "Info");
if (frame.GetSettableTextWidth)
   frameWidth = frame.GetSettableTextWidth();

var tm = new FusionProTextMeasure;
tm.font = "Arial"; // change to your font
tm.pointSize = 20 * 100; // change to your point size

var widest = 0;
var r = [];
for (var i in fields)
{
   var val = TaggedDataField(fields[i][1]);
   if (!val)
       continue;

   var text = '<span color="Red">' + fields[i][0] + '</span> ' + val;
   tm.CalculateTextExtent(text);
   widest = Math.max(widest, tm.textWidth);
   r.push(text);
}

var indent = frameWidth - widest - (0.25 * 7200); // .25 inch right margin
return '<p br=false findent=' + indent + ' lindent=' + indent + '>\n' + r.join('<br>\n');

I think that should meet all the stated requirements. If it's not working as you expect, then please post the collected job.

Edited by Dan Korn
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...