davers Posted January 25, 2011 Share Posted January 25, 2011 Is it possible to set column widths automatically depending on the longest Field value? And also set a maximum width for the column? I'm trying to create a bilingual envelope (see attached) where the gutter width is fixed, and begins after the longest row in first column. Column 1 has a maximum width of 2.5"envelopeColumns.pdf Quote Link to comment Share on other sites More sharing options...
esmith Posted January 27, 2011 Share Posted January 27, 2011 I think that could be done with a rule involving TextMeasurements and tagged tabs, but are you expecting the rule to determine the break of the bold text in each "column" or is that already broken to 2 lines via tagged data? Quote Link to comment Share on other sites More sharing options...
davers Posted January 27, 2011 Author Share Posted January 27, 2011 Hi Eric, The rule must determine the break in the text once it reaches a maximum width of 2.5", with no hyphenations. As the example, only the first line will be bold. Thanks for the response, Domenic Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted January 27, 2011 Share Posted January 27, 2011 (edited) Assuming that the blocks of text are in two Formatted Text resources named "English Address Block" and "French Address Block", and that your text frame is named "Address", this should work: // These should match your resource and frame names, and width requirements: var textFirstColumn = Resource("English Address Block").content; var textSecondColumn = Resource("French Address Block").content; var targetFrameName = "Address"; var maxColumnWidthInches = 2.5; var GutterWidthInches = 0.2; // Don't edit below here! if (FusionPro.inValidation) textFirstColumn = "This only works in composition."; var FrameWidth = FindTextFrame(targetFrameName).GetSettableTextWidth(); var tm = new FusionProTextMeasure; tm.CalculateTextExtent(textFirstColumn); if (tm.messages) ReportError("Text Measurement error: " + tm.messages); var FirstColumnWidth = Math.min(tm.textWidth, maxColumnWidthInches * 7200); var GutterWidth = GutterWidthInches * 7200; var table = new FPTable; table.AddColumns(FirstColumnWidth, GutterWidth, FrameWidth - GutterWidth - FirstColumnWidth); table.AddRows(1); //table.Rows[0].Cells[0].SetBorders("Thin", "Black", "Top", "Bottom", "Left", "Right"); var CellMargins = new FPTableMargins; CellMargins.Top = 0; CellMargins.Bottom = 0; CellMargins.Left = 0; CellMargins.Right = 0; table.Rows[0].Cells[0].Content = textFirstColumn; table.Rows[0].Cells[0].Margins = CellMargins; table.Rows[0].Cells[2].Content = textSecondColumn; table.Rows[0].Cells[2].Margins = CellMargins; return table.MakeTags(); Edited January 27, 2011 by Dan Korn Quote Link to comment Share on other sites More sharing options...
davers Posted February 4, 2011 Author Share Posted February 4, 2011 Thanks for the reply Dan, I created the Formatted Text Resources and named the Text Frame "Address", but I get an error message line 22: ReferenceError : FPTable is not defined. I attached a screenshot. What am I doing wrong? How can I fix that? // I have a very limited knowledge of JavaScript!; Thanks, Domenic Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted February 4, 2011 Share Posted February 4, 2011 line 22: ReferenceError : FPTable is not defined. I attached a screenshot. What am I doing wrong? How can I fix that? Oh, you're using version 6. The FPTable object is new in FusionPro 7.0. For earlier versions of FusionPro, this can done by outputting the table tags directly. Please refer to the Tags Reference Guide. Quote Link to comment Share on other sites More sharing options...
davers Posted February 10, 2011 Author Share Posted February 10, 2011 Hi Dan, I went through the Tag Reference Guide, and they just give examples on how to set specific column widths. My first and third column widths are dependent on variable data to a maximum width of 2.5", the 2nd column (gutter) is a fixed width Domenic Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted February 10, 2011 Share Posted February 10, 2011 I went through the Tag Reference Guide, and they just give examples on how to set specific column widths. My first and third column widths are dependent on variable data to a maximum width of 2.5", the 2nd column (gutter) is a fixed width Yes, you'll have to take the code from the example I posted: var table = new FPTable; table.AddColumns(FirstColumnWidth, GutterWidth, FrameWidth - GutterWidth - FirstColumnWidth); table.AddRows(1); And port it to output the table tags directly, like so: var table = '<table columns=3>'; table += '<column width=' + FirstColumnWidth + '>'; table += '<column width=' + GutterWidth + '>'; table += '<column width=' + (FrameWidth - GutterWidth - FirstColumnWidth) + '>'; And so on. Or you'll need to update to FusionPro 7 to use the FPTable object. Quote Link to comment Share on other sites More sharing options...
davers Posted January 16, 2013 Author Share Posted January 16, 2013 Hi Dan, Thanks for your help. We have updated to version 7.2 and I was able to use your original code for creating 2 columns. 3 questions: 1) How do i get the columns to align at the bottom of the text box. Clicking the align bottom button on the Text Frame palette doesn't work, neither does entering code "table.Rows[0].Cells[0].VAlign = "Bottom";". 2) Regarding your original code, when i create the Formatted Text Resources and place Rules in it, it won't display correctly in my preview. Any suggestions? 3) If i can't use Rules in the Formatted Text Resources, how do i prevent a line breaking after a space in a field e.g. the postal code H2E 4X2 will break onto the next line? Thanks Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted January 16, 2013 Share Posted January 16, 2013 Thanks for your help. We have updated to version 7.2 and I was able to use your original code for creating 2 columns. Okay, you're still a bit behind the latest 8.2 version, but 7.2 is a good step up from where you were. 3 questions: 1) How do i get the columns to align at the bottom of the text box. Clicking the align bottom button on the Text Frame palette doesn't work, neither does entering code "table.Rows[0].Cells[0].VAlign = "Bottom";". Add these lines near the top: textFirstColumn = textFirstColumn.replace(/<p /gi, '<p cellalignment="bottom" '); textSecondColumn = textSecondColumn.replace(/<p /gi, '<p cellalignment="bottom" ');The problem is that "cellalignment" is an attribute of the <p> tag, not of the <cell> tag, so while it gets set properly on the first paragraph of the text from the Formatted Text Resource, it gets overridden again by subsequent <p style="(no style)"> tags. (I suppose that FusionPro should be changed so that vertical alignment is truly a property of the cell.) 2) Regarding your original code, when i create the Formatted Text Resources and place Rules in it, it won't display correctly in my preview. Any suggestions? Exactly how is it not displaying correctly? Calling out a rule works fine for me in my little test job. I would do a full composition (not a Preview) and look for any warnings in the log (.msg) file. 3) If i can't use Rules in the Formatted Text Resources, how do i prevent a line breaking after a space in a field e.g. the postal code H2E 4X2 will break onto the next line? Well, generally, you can do something like this to prevent text from breaking: return Field("postal code").replace(/ /g, " ");But that would still require a rule to be called out from the resource. So we need to figure out your question 2. Although an alternative would be to just hard-code all the tags for the address blocks instead of maintaining them in the Text Editor as Formatted Text Resources. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.