Jump to content

Fitting a variable table into a static space


Lord Karl

Recommended Posts

First off let me say thanks to everyone for this Forum, I use it a lot and appreciate all the input. I'm using FP 8.2.5 on Win7, for the record.

 

I have built a variable form within a customer file; there are multiple tables and I'm having an issue with row height in the tables. I've seen posts where it states that there is no control over the row height but I'm hoping there's another solution for my issue. In some instances the table overruns the allotted space for the data; I am trying to figure a way to remove the spaces between lines.

 

I'm marginal in HTML and coding; I've built this so far using a mix of copy/paste from another project and trial and error from posts here. There's probably some obvious solution but I'm not seeing it.

 

As you can see from the attached screen shot the data in Your Company Paid Benefits is overlapping the next bar down; the customer would like the whole thing at font size 11 and I reduced it to 10 to make everything else fit, but in this particular field even 8.5 pt font is not working.

 

While I'm at it, I also need to figure how to right justify the text in the money cells...

 

My code for the table in question is:

var table = new FPTable;

var CurrentRow = 0;

 

table.AddColumns(44000,8600);

table.AddRows(6);

 

for(var Col=0;Col<=2;Col++)

 

{

 

if(Trim(Field("BEST Choice Dol")) !="")

{

table.Rows[CurrentRow].Cells[0].Content = "B.E.S.T. Choice Dollars";

table.Rows[CurrentRow].Cells[1].Content = "$"+Field("BEST Choice Dol");

CurrentRow++;

}

if(Trim(Field("Fueling Your He")) !="")

{

table.Rows[CurrentRow].Cells[0].Content = "Fueling Your Health Credit";

table.Rows[CurrentRow].Cells[1].Content = "$"+Field("Fueling Your He");

CurrentRow++;

}

if(Trim(Field("******* Dental ")) !="")

{

table.Rows[CurrentRow].Cells[0].Content = "******* & Dental Premium - Employer";

table.Rows[CurrentRow].Cells[1].Content = "$"+Field("******* Dental ");

CurrentRow++;

}

if(Trim(Field("Workers Comp")) !="")

{

table.Rows[CurrentRow].Cells[0].Content = "Worker's Compensation";

table.Rows[CurrentRow].Cells[1].Content = "$"+Field("Workers Comp");

CurrentRow++;

}

if(Trim(Field("Federal State U")) !="")

{

table.Rows[CurrentRow].Cells[0].Content = "Federal & State Unemployment";

table.Rows[CurrentRow].Cells[1].Content = "$"+Field("Federal State U");

CurrentRow++;

}

if(Trim(Field("Company Paid Be")) !="")

{

table.Rows[CurrentRow].Cells[0].SetBorders ("Thin", "Ferrell Blue", "Top");

table.Rows[CurrentRow].Cells[1].SetBorders ("Thin", "Ferrell Blue", "Top");

table.Rows[CurrentRow].Cells[0].Content = '<f name="HelveticaNeueLt Std">'+"Total";

table.Rows[CurrentRow].Cells[1].Content = "$"+Field("Company Paid Be");

CurrentRow++;

}

 

return table.MakeTags()};

 

Thanks in advance for assistance, and if I left anything out let me know!

Row spacing.pdf

Link to comment
Share on other sites

Because of the limitations with copyfitting with tables and not being able to set a table height, you'd probably be better off scrapping the table all together. If you do that, you can have two text frames named "CompanyPaid" and "Retirement" set to the size you'd like to restrict the text to with copyfit applied to them. That way they'll never bleed into a section they don't belong in.

 

Here's an example of how I would set up the code for the line items in the "CompanyPaid" text frame:

var textFrame = "CompanyPaid";
var coPaid = [
   ["BEST Choice Dollars", Field("BEST Choice Dol")],
   ["Fueling Your Health Credit", Field("Fueling Your He")],
   ["******* & Dental Premium - Employer", Field("******* Dental ")],
   ["Worker's Compensation", Field("Workers Comp")],
   ["Federal & State Unemployment", Field("Federal State U")]
];

// Set tab to just under the width of the frame
var tab = '"0;' + (FindTextFrame(textFrame).width - 100) + ',Right,,,;"';

// filter out empties
coPaid = coPaid.filter(function(s){ return Trim(s[1])});

// add tabs to force justify the line items
coPaid = coPaid.map(function(p){ return '<p br=false tabstops=' + tab + '>' +  p[0] + '<t>$' + Trim(p[1]);});

// add line breaks
coPaid = coPaid.join('<br>');

return coPaid;

 

The only real benefit to using tables here, is the border you're placing above your 'total' line. With the approach I've illustrated above, I would suggest making a PDF graphic of that color you're using and place an inline graphic above the "total" at the width of the text frame:

'<graphic file="path/to/color.pdf" width=' + FindTextFrame(textFrame).width + ' height=300>';

 

I'm sure someone has a better suggestion but hopefully that will get you started!

Link to comment
Share on other sites

Appreciate the help; this looks great. When I attempted to enter in another line (the Totals line) it gives me an error:

TypeError: s has no properties.

 

s is the function in the line to filter out empties, I see that but don't get why adding a line of data is throwing that. When I take my new line of data back out of course it works, but I'm at a loss. Sorry for my ignorance...

 

As long as I'm being dense here, I placed the line image in Resources but when I put the line in to place the image I am getting a syntax error, needing a closing ]. If I add that in but leave the semicolon it gives the same error, if I remove the semicolon then the error is that it's missing variable name. Here's the code - variable names have changed as I'm doing 4 separate frames but the base idea is the same.

var textFrame = "BasePay";

var coPaid = [

["Compensation", Field("Compensation")],

["Overtime", Field("Overtime")],

["Commission", Field("Commission")],

'<graphic file="path/to/color.pdf" width=' + FindTextFrame(textFrame).width + ' height=300>';

['<f name="HelveticaNeueLt Std">'+"Total", Field("Base Pay")],

];

 

// Set tab to just under the width of the frame

var tab = '"0;' + (FindTextFrame(textFrame).width - 100) + ',Right,,,;"';

 

// filter out empties

coPaid = coPaid.filter(function(s){ return Trim(s[1])});

 

// add tabs to force justify the line items

coPaid = coPaid.map(function(p){ return '<p br=false tabstops=' + tab + '>' + p[0] + '<t>$' + Trim(p[1]);});

 

// add line breaks

coPaid = coPaid.join('<br>');

 

return coPaid;

Edited by Lord Karl
Link to comment
Share on other sites

You don't need to add those elements to the coPaid array. In fact, adding them (the graphic specifically) would give you weird results. Namely because 'coPaid" is a multi dimensional array made up of arrays of the line item description and line item value and adding a single value (graphic) will cause an error. I'd suggest simply tacking those unique elements to the end of that array like so:

var result = coPaid.join('<br>');
result += '<graphic file="path/to/color.pdf" width=' + FindTextFrame(textFrame).width + ' height=300>';
result += '<p tabstops=' + tab + '><f name="HelveticaNeueLt Std">Total' + '<t>$' + Trim(Field("Base Pay"));
return result;

Link to comment
Share on other sites

Thanks for your efforts; when I put the code in it is either giving me a syntax error or when I try to fix that it disrupts the flow entirely and still doesn't do what I'm looking for. I'm sorry for being a hassle.

 

If I have this it loses the formatting, everything shifts left, the empty lines are in there and there's no line:

var textFrame = "BasePay";

var coPaid = [

["Compensation", Field("Compensation")],

["Overtime", Field("Overtime")],

["Commission", Field("Commission")],

];

var result = coPaid.join('<br>');

result += '<graphic file="Greenline" width=' + FindTextFrame(textFrame).width + ' height=300>';

result += '<p tabstops=' + tab + '><f name="HelveticaNeueLt Std">Total' + '<t>$' + Trim(Field("Base Pay"));

return result;

 

// Set tab to just under the width of the frame

var tab = '"0;' + (FindTextFrame(textFrame).width - 100) + ',Right,,,;"';

 

// filter out empties

coPaid = coPaid.filter(function(s){ return Trim(s[1])});

 

// add tabs to force justify the line items

coPaid = coPaid.map(function(p){ return '<p br=false tabstops=' + tab + '>' + p[0] + '<t>$' + Trim(p[1]);});

 

// add line breaks

coPaid = coPaid.join('<br>');

 

 

 

return coPaid;

 

I've played around with different things but I haven't been able to get anything working so far.

Link to comment
Share on other sites

The code should be this:

var textFrame = "CompanyPaid";
var coPaid = [
   ["BEST Choice Dollars", Field("BEST Choice Dol")],
   ["Fueling Your Health Credit", Field("Fueling Your He")],
   ["******* & Dental Premium - Employer", Field("******* Dental ")],
   ["Worker's Compensation", Field("Workers Comp")],
   ["Federal & State Unemployment", Field("Federal State U")]
];

// Set tab to just under the width of the frame
var tab = '"0;' + (FindTextFrame(textFrame).width - 100) + ',Right,,,;"';

// filter out empties
coPaid = coPaid.filter(function(s){ return Trim(s[1])});

// add tabs to force justify the line items
coPaid = coPaid.map(function(p){ return '<p br=false tabstops=' + tab + '>' +  p[0] + '<t>$' + Trim(p[1]);});

// add line breaks
var result = coPaid.join('<br>');

result += '<graphic file="Greenline" width=' + FindTextFrame(textFrame).width + ' height=300>';
result += '<p tabstops=' + tab + '><f name="HelveticaNeueLt Std">Total' + '<t>$' + Trim(Field("Base Pay"));
return result;

 

And make sure that you don't put a comma after the last array in the "coPaid" array:

var coPaid = [
["Compensation", Field("Compensation")],
["Overtime", Field("Overtime")],
["Commission", Field("Commission")][color="Red"],[/color]
];

Link to comment
Share on other sites

Thank you sir. I see what I was doing wrong with the format to screw the syntax up; when I place it now the text is all correct but it's not finding the Greenline.pdf - it's just placing the text with no line in there.

 

I added the pdf as a resource; I've tried it with the code as you sent and also replacing the filename with Resource("Greenline") and it's the same result either way. Text is correct, no line.

 

I played with the height and took it way up, still no change - makes me think it's not finding the file in the first place?

Link to comment
Share on other sites

Thank you sir. I see what I was doing wrong with the format to screw the syntax up; when I place it now the text is all correct but it's not finding the Greenline.pdf - it's just placing the text with no line in there.

 

I added the pdf as a resource; I've tried it with the code as you sent and also replacing the filename with Resource("Greenline") and it's the same result either way. Text is correct, no line.

 

I played with the height and took it way up, still no change - makes me think it's not finding the file in the first place?

You mean this?

result += '<graphic file="Greenline" width=' + FindTextFrame(textFrame).width + ' height=300>';

Unless the graphic's file name really is just "Greenline", with no extension, then yeah, that won't work. There's probably an error message in your composition log (.msg) file if you compose (not preview) telling you as much.

 

You should either use the actual file name, which I assume has the extension ".pdf":

result += '<graphic file="Greenline.pdf" width=' + FindTextFrame(textFrame).width + ' height=300>';

Or use the resource name with the "resource" attribute instead of "file":

result += '<graphic resource="Greenline" width=' + FindTextFrame(textFrame).width + ' height=300>';

 

You might also want to use the GetSettableTextWidth() method of the frame object, instead of the width parameter, as the method takes things like text inset and border into account:

result += '<graphic file="Greenline.pdf" width=' + FindTextFrame(textFrame).GetSettableTextWidth() + ' height=300>';

Link to comment
Share on other sites

GetSettableWidth got the line in there, woohoo! For some reason, the last row of text ABOVE the line lost it's force format though... The rest of the lines look fine, but the last line shows as

 

Federal & State Unemployment$295.50

instead of the $295.50 being at the right edge of the text box. The only code I altered was the GetSettableWidth line, and if I take that back out the force format returns (and the box goes away of course).

Link to comment
Share on other sites

Checking back on this project; not trying to be a hassle, just checking to see if anyone had any advice. When I entered the code as suggested the line works great, but the last data row above the line loses formatting. Code looks like this, and I attached a screen shot. Not sure why it's losing the tabbing on the last row?

 

var textFrame = "CompanyPaid";

var coPaid = [

["B.E.S.T. Choice Dollars", Field("BEST Choice Dol")],

["Fueling Your Health Credit", Field("Fueling Your He")],

["******* & Dental Premium - Employer", Field("******* Dental ")],

["Worker's Compensation", Field("Workers Comp")],

["Federal & State Unemployment", Field("Federal State U")]

];

 

// Set tab to just under the width of the frame

var tab = '"0;' + (FindTextFrame(textFrame).width - 100) + ',Right,,,;"';

 

// filter out empties

coPaid = coPaid.filter(function(s){ return Trim(s[1])});

 

// add tabs to force justify the line items

coPaid = coPaid.map(function(p){ return '<p br=false tabstops=' + tab + '>' + p[0] + '<t>$' + Trim(p[1]);});

 

// add line breaks

var result = coPaid.join('<p>');

 

result += '<graphic file="Blueline.pdf" width=' + FindTextFrame(textFrame).GetSettableTextWidth() + ' height=300>';

result += '<p tabstops=' + tab + '><f name="HelveticaNeueLt Std">Total' + '<t>$' + Trim(Field("Company Paid Be"));

return result;

Screenshot.pdf

Link to comment
Share on other sites

You need a line break before the inline graphic. The easiest way to do this is to put a <br> tag before the <graphic> tag, on the third-to-last line of your rule:

result += '<br><graphic file="Blueline.pdf" width=' + FindTextFrame(textFrame).GetSettableTextWidth() + ' height=300>';

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