Jump to content

Variable Text Box Sizing


bkurzbuch

Recommended Posts

Hello All

 

I have a job with a text box that has a frame on it. Text is centered vertically. My problem is, how to adjust the text box size if one or more variables is not present. I believe this will have to be done with a table, but I have no experience setting up a table. PDF attached. If any of the variable percentages is zero the that text will not print and the rest moves up also resizing the frame around the box. Thanks for your help

Variable_Sample.pdf

Link to comment
Share on other sites

You can create several text boxes and suppress them in OnRecordStart rule based on data. You can also create # number of pages and set the page to not be used also.

 

Creating a table is nice too and you should be able to find something on the forum here.

Link to comment
Share on other sites

It's hard to tell what part of the text in your sample is variable, but you should be able to do something like this:

  1. Copy all of the contents of the text frame (from the Text Editor).
  2. Click the Create Resources tool (or use the Steps palette).
  3. Click Add and set the resource Type to Formatted Text.
  4. Click Edit, and paste in the contents from the text frame.
  5. Click OK in the Text Editor, name the resource, and click OK a couple times to save the changes.
  6. Add a new JavaScript rule with this syntax:
    var text = Resource("YourResourceName").content; // <- set resource name
    var table = new FPTable;
    table.AddColumn(7200 * 3); // <- set the width for all the text, in hundredths of points (7200 * the number of inches)
    var row = table.AddRow()
    row.Cells[0].Content = text;
    row.Cells[0].SetBorders("Thin", "Black", "Top", "Bottom", "Left", "Right");
    return table.MakeTags();
    


  7. Change the resource name and the column width as noted.
  8. Check "Treat returned strings as tagged text", name the rule, and save it.
  9. Edit the text frame again to simply call out the new rule.

You could, of course, just build up the text for the table in the rule, without creating a Formatted Text resource.

 

If you do use a resource and you want to automatically skip the content that's not applicable, you can open up the resource, select all of the text in it, then click Paragraph, check the "Suppress if" box and change the drop-down from "Empty" to "Containing Empty Variables."

Link to comment
Share on other sites

Hi Dan

You are the best. Thank You very much. i have 1 quick questions and I can close this project out. I have attached a sample of the output. The Remove if "Containing Empty Variables."is only removing the last line of the paragraphs. On the attached sample you can see under Payroll deduction. The line "Up to (field)%. is dropping out when empty, but not the corresponding lines above it. Any advise. Thanks again, very elegant coding.

Dan_Rule_Sample.pdf

Link to comment
Share on other sites

Hi Dan

You are the best. Thank You very much. i have 1 quick questions and I can close this project out. I have attached a sample of the output. The Remove if "Containing Empty Variables."is only removing the last line of the paragraphs. On the attached sample you can see under Payroll deduction. The line "Up to (field)%. is dropping out when empty, but not the corresponding lines above it. Any advise. Thanks again, very elegant coding.

I can't tell what might be going wrong just by looking at the output. Can you post the template?

 

Are you sure that you selected ALL of the text in the Formatted Text Resource before clicking the Paragraph button and applying the "Suppress if containing empty variables" setting?

Link to comment
Share on other sites

Morning Dan

Yes, I did select all the text. I went back and double checked that and that the return string as tagged text was selected, before I posted again. The template is attached. Thanks for taking look.

 

I was able to get this to work by changing the three paragraphs that have to drop out with a separate text resource and calling out a rule in the main text resource.

But for my own info/learning experience I would like to know why it didn't work as per your suggestion. thanks again for your help. Always appreciated.

371513_77834 Duke AH Ltr L21389 Q217_ccg.zip

Link to comment
Share on other sites

Morning Dan

Yes, I did select all the text. I went back and double checked that and that the return string as tagged text was selected, before I posted again. The template is attached. Thanks for taking look.

 

I was able to get this to work by changing the three paragraphs that have to drop out with a separate text resource and calling out a rule in the main text resource.

But for my own info/learning experience I would like to know why it didn't work as per your suggestion. thanks again for your help. Always appreciated.

Okay, thanks. It wasn't obvious at all by looking at the output, but from the template, I can see that you've manually broken up the text into separate paragraphs, not all of which contain a variable to trigger the "Suppress if containing empty variables" setting. You need to keep each block of text as a single paragraph. The easiest way to do this is to either (a) remove all of the line/paragraph breaks within each paragraph, or (b) replace the "hard" paragraph breaks (<p> tags) with "soft" returns (<br> tags), by holding down the Shift key while pressing Enter/Return. The only problem is that, in the Text Editor, the "hard" and "soft" line breaks look the same; but you can see the difference in the tags generated by using the "View Source" button in the Resource Editor.

 

Also, you could remove the empty lines for spacing between the paragraphs and use the "Space above" and "Space below" settings on the Paragraph Formatting dialog instead. (You could also accomplish some of the spacing with margins in the table.)

 

I've attached an updated version of your template which uses soft returns and Space Above in the Text Resource to ensure that the "Suppress if containing empty variables" setting applies to each paragraph as a whole.

 

So this strategy does work, if you take into account what FusionPro considers to be an entire paragraph. That said, I think we're on the edge here of what can be accomplished with formatting in the GUI, and it might be easier to control things more precisely by building up the text in the rule, like so:

var paras = 
[
   ["ANTI THEFT", "Drive a vehicle with<br>an anti-theft device?"],
   ["PAYROLL", "Pay your<br>premiums through<br>payroll deduction?"],
   ["CAR AND HOME", "Insure both your vehicle<br>and your home through<br>the same company?"],
   ["PARK GARAGE", "Park your vehicle in<br>a garage at night?"],
];

var table = new FPTable;
table.AddColumn(14400); // <- set the width for all the text, in hundredths of points (7200 * the number of inches)
var row = table.AddRow();
row.Cells[0].Margins = { Top:400, Bottom:100, Left:0, Right:0 };
row.Type = "Header";
row.Cells[0].Content = "<b>Available Discounts</b>";
row = table.AddRow();
row.Cells[0].Content = "For being a<br>Duke employee.<br>Up to 15%<superscript>2</superscript>";
for (var p in paras)
{
   var para = paras[p];
   var fieldName = para[0];
   var text = para[1];
   var fieldVal = Field(fieldName);
   if (fieldVal)
   {
       text += "<br>Up to " + fieldVal + "%";
       row = table.AddRow();
       row.Cells[0].Content = text;
   }
}
table.Rows[table.Rows.length-1].Cells[0].Margins = { Top:100, Bottom:400, Left:0, Right:0 }; // last row bottom margin
table.SetBorders("Thin", "Black", "Top", "Bottom", "Left", "Right");
return table.MakeTags();

371513_77834 Duke AH Ltr L21389 Q217_ccg-Dan.pdf

Link to comment
Share on other sites

Dan

 

Thank you very much for taking the time to look at this and the detailed explanation. My thoughts where the same, that it wasn't see it as separate paragraphs, but was unsure how to fix that problem. Thanks again. I learn so much from this forum. Truly a great asset.

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