Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > FusionPro® VDP Creator

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 8th, 2019, 07:24 AM
designerspressinc designerspressinc is offline
Junior Community Member
 
Join Date: May 2012
Location: Orlando, Florida
Posts: 19
Default Formatting Headache Redux

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?
Reply With Quote
  #2  
Old July 9th, 2019, 02:13 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,312
Default Re: Formatting Headache Redux

Something like this:
Code:
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.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #3  
Old July 10th, 2019, 06:49 AM
designerspressinc designerspressinc is offline
Junior Community Member
 
Join Date: May 2012
Location: Orlando, Florida
Posts: 19
Default Re: Formatting Headache Redux

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.
__________________
FusionPro VDP Creator 10.0.26
Mac OSX 10.14.5
Acrobat 11.0.07

Last edited by designerspressinc; July 10th, 2019 at 07:00 AM..
Reply With Quote
  #4  
Old July 10th, 2019, 10:39 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,312
Default Re: Formatting Headache Redux

Quote:
Originally Posted by designerspressinc View Post
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:
Code:
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.
Quote:
Originally Posted by designerspressinc View Post
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.
Quote:
Originally Posted by designerspressinc View Post
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:
Code:
    var text = '<span color="Red">' + fields[i][0] + '</span> ' + val;
With whatever color name you want.
Quote:
Originally Posted by designerspressinc View Post
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.
Quote:
Originally Posted by designerspressinc View Post
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.
Quote:
Originally Posted by designerspressinc View Post
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:
Code:
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.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});

Last edited by Dan Korn; July 10th, 2019 at 10:48 AM..
Reply With Quote
  #5  
Old July 10th, 2019, 11:45 AM
designerspressinc designerspressinc is offline
Junior Community Member
 
Join Date: May 2012
Location: Orlando, Florida
Posts: 19
Smile Re: Formatting Headache Redux

Thanks Dan. I really appreciate the help. That seems to have done the trick with the modifications you suggested.
__________________
FusionPro VDP Creator 10.0.26
Mac OSX 10.14.5
Acrobat 11.0.07
Reply With Quote
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 10:04 PM.


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