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

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old December 28th, 2017, 01:46 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: My First Table - help!

Quote:
Originally Posted by Kim View Post
That HAlign centers ALL the cells. I was wondering if it's possible to just center the header and leave the actual dates and amounts under those headers flush left?
It's done the same way:
Code:
for (var i = rec; i <= data.recordCount; i++) {
  function ExField(str) { return TaggedTextFromRaw(data.GetFieldValue(i, str)); }
  if (ExField('company') && i > rec) break;

  var row = table.AddRow();
  row.Cells[0].HAlign = 'Left';
  row.CopyCells(0, 1);
  row.SetContents.apply(row, ['Date', 'Amount'].map(ExField));
}
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #12  
Old December 28th, 2017, 03:42 PM
Kim Kim is offline
Regular Contributor
 
Join Date: Sep 2008
Posts: 69
Smile Re: My First Table - help!

Thanks for your patience with me, Ste.

It looks great!
__________________
Fusion Pro Desktop 10.0.16 & Server • Acrobat Pro DC • Mac OSX 10.12
Reply With Quote
  #13  
Old December 28th, 2017, 05:38 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,388
Default Re: My First Table - help!

Here's Ste's rule adapted to use the multi-line record feature in FP 10. (It's back to a regular rule named "RUL_table", as in the original template you posted, not an OnRecordStart rule.)
Code:
var numOfCols = 3;
var data = FusionPro.GetMultiLineRecords();

var table = new FPTable();
table.AddColumns(7200, 8500);

var header = table.AddRow();
header.Type = 'Header';
var cell = header.Cells[0];
cell.SetBorders('Thin', 'Black', 'Bottom');
cell.HAlign = 'Center';
header.CopyCells(0, 1);
header.SetContents('Date', 'Amount');


for (var i = 1; i <= data.recordCount; i++) {
  function ExField(str) { return TaggedTextFromRaw(data.GetFieldValue(i, str)); }
  var row = table.AddRow();
  row.Cells[0].HAlign = 'Left';
  row.CopyCells(0, 1);
  row.SetContents.apply(row, ['Date', 'Amount'].map(ExField));
}

// Number of rows needed to evenly distribute across numOfCols.
// Minus 1 for the header row.
var rows = Math.ceil((table.Rows.length - 1) / numOfCols);

// Duplicate column 1 and 2 (and their headers) to make up numOfCols.
for (var i = 0; i < (numOfCols - 1) * 2; i++) {
  table.Columns.push(table.Columns[i % 2]);
  table.Rows[0].Cells.push(table.Rows[0].Cells[i % 2])
}

// Concatenate the rows cells in order to reduce our total rows
// and fill up the extra columns. 
var rowCounter = 1;
while ((table.Rows.length - 1) > rows) {
  var index = rowCounter % rows || rows;
  var row = table.Rows.splice(rows + 1, 1).pop();
  table.Rows[index].Cells = table.Rows[index].Cells.concat(row.Cells)
  rowCounter++
}

// Return the table tags.
return table.MakeTags();
__________________
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
  #14  
Old December 28th, 2017, 06:01 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,388
Default Re: My First Table - help!

You could also accomplish this with a multi-column text frame, which makes the rule much simpler, since you only need a two-column table to flow into those three text frame columns. The only tricky part is the text that spans all columns after the table, but that's just a matter of using the <p paragraphplacement="straddleall"> tag. See the attached template.
Attached Files
File Type: pdf MultiLine_Sample-Dan-2.pdf (50.0 KB, 9 views)
__________________
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
  #15  
Old January 4th, 2018, 12:00 PM
Kim Kim is offline
Regular Contributor
 
Join Date: Sep 2008
Posts: 69
Default Re: My First Table - help!

Thanks, Dan!

A thing of beauty (as always) and great to see how to accomplish in v10.
Sorry for my slow response, been out of the office.

Happy New Year and thanks again to you both!!
Kim
__________________
Fusion Pro Desktop 10.0.16 & Server • Acrobat Pro DC • Mac OSX 10.12
Reply With Quote
  #16  
Old January 12th, 2018, 04:42 PM
Kim Kim is offline
Regular Contributor
 
Join Date: Sep 2008
Posts: 69
Default Re: My First Table - help!

Hi Dan and Ste,

Remember this thoroughly beautiful table you helped me work out?

I wound up using the code below for v10 and it's great and just what I asked for. But now that I've got some real data, I've got a little wrinkle. Sometimes there is only 1 entry for Date and Amount. So, I don't need 3 columns in those cases, but it still outputs the Date Amount headers for all 3 columns.

Any ideas on how to show the Date and Amount headers only if there is content to warrant them?

Code:
var numOfCols = 3;
var data = FusionPro.GetMultiLineRecords();

var table = new FPTable();
table.AddColumns(6000, 7000, 3000);

var header = table.AddRow();
header.Type = 'Header';
var cell = header.Cells[0];
cell.SetBorders('Thin', 'Black', 'Bottom');
cell.HAlign = 'Left';
header.CopyCells(0, 1);
header.SetContents('Date', 'Amount');


for (var i = 1; i <= data.recordCount; i++) {
  function ExField(str) { return TaggedTextFromRaw(data.GetFieldValue(i, str)); }
  var row = table.AddRow();
  row.Cells[0].HAlign = 'Left';
  row.CopyCells(0, 1);
  row.SetContents.apply(row, ['Date', 'Amount'].map(ExField));
}

// Number of rows needed to evenly distribute across numOfCols.
// Minus 1 for the header row.
var rows = Math.ceil((table.Rows.length - 1) / numOfCols);

// Duplicate column 1 and 2 (and their headers) to make up numOfCols.
for (var i = 0; i < (numOfCols - 1) * 3; i++) {
  table.Columns.push(table.Columns[i % 3]);
  table.Rows[0].Cells.push(table.Rows[0].Cells[i % 3])
}

// Concatenate the rows cells in order to reduce our total rows
// and fill up the extra columns. 
var rowCounter = 1;
while ((table.Rows.length - 1) > rows) {
  var index = rowCounter % rows || rows;
  var row = table.Rows.splice(rows + 1, 1).pop();
  table.Rows[index].Cells = table.Rows[index].Cells.concat(row.Cells)
  rowCounter++
}

// Return the table tags.
return table.MakeTags();
Thanks!
Kim
__________________
Fusion Pro Desktop 10.0.16 & Server • Acrobat Pro DC • Mac OSX 10.12
Reply With Quote
  #17  
Old January 12th, 2018, 07:38 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: My First Table - help!

I haven't tested this but it seems like it would give you what you're looking for:
Code:
var numOfCols = 3;
var data = FusionPro.GetMultiLineRecords();

var table = new FPTable();
table.AddColumns(6000, 7000, 3000);

var header = table.AddRow();
header.Type = 'Header';
header.Cells[0].SetBorders('Thin', 'Black', 'Bottom');
header.CopyCells(0, 1);
header.SetContents('Date', 'Amount');


for (var i = 1; i <= data.recordCount; i++) {
  function ExField(str) { return TaggedTextFromRaw(data.GetFieldValue(i, str)); }  
  
  // Skip this record if 'Date' & 'Amount' fields are both empty.
  var contents = ['Date', 'Amount'].map(ExField);
  if (!Trim(contents.join(''))) continue;
  var row = table.AddRow();
  row.SetContents.apply(row, contents);
}

// Determine how many columns are needed based on how many rows
// were added to the table (minus 1 for the header row).
var colsNeeded = table.Rows.length - 1;

// Update the numOfCols variable if we need less than 3.
numOfCols = colsNeeded < numOfCols ? colsNeeded : numOfCols;

// Number of rows needed to evenly distribute across numOfCols.
var rows = Math.ceil(colsNeeded / numOfCols);

// Duplicate column 1 and 2 (and their headers) to make up numOfCols.
for (var i = 0; i < (numOfCols - 1) * 3; i++) {
  table.Columns.push(table.Columns[i % 3]);
  table.Rows[0].Cells.push(table.Rows[0].Cells[i % 3])
}

// Concatenate the rows cells in order to reduce our total rows
// and fill up the extra columns. 
var rowCounter = 1;
while (colsNeeded > rows) {
  var index = rowCounter % rows || rows;
  var row = table.Rows.splice(rows + 1, 1).pop();
  table.Rows[index].Cells = table.Rows[index].Cells.concat(row.Cells)
  rowCounter++
}

// Return the table tags.
return table.MakeTags();
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #18  
Old January 15th, 2018, 10:40 AM
Kim Kim is offline
Regular Contributor
 
Join Date: Sep 2008
Posts: 69
Default Re: My First Table - help!

Hi Ste!

Thanks for the response. This is almost perfect. I thought it was doing it exactly as needed, but have found that it behaves a little weird when there are 4 records - it makes 2 columns with 2 lines each and puts a blank 3rd column with just headers. If I have 3 records it is fine and does 3 columns across. It just seems to get confused by 4 records.

Examples of the one scenario that doesn't work attached along with examples of other record counts working as expected.
Attached Images
File Type: png good1.png (10.0 KB, 4 views)
File Type: png bad.png (5.8 KB, 4 views)
File Type: png good2.png (4.9 KB, 4 views)
File Type: png good3.png (6.7 KB, 3 views)
File Type: png good4.png (5.9 KB, 2 views)
__________________
Fusion Pro Desktop 10.0.16 & Server • Acrobat Pro DC • Mac OSX 10.12

Last edited by Kim; January 15th, 2018 at 11:01 AM..
Reply With Quote
  #19  
Old January 17th, 2018, 08:25 AM
Kim Kim is offline
Regular Contributor
 
Join Date: Sep 2008
Posts: 69
Default Re: My First Table - help!

Have I stumped you guys?
__________________
Fusion Pro Desktop 10.0.16 & Server • Acrobat Pro DC • Mac OSX 10.12
Reply With Quote
  #20  
Old January 17th, 2018, 10:36 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: My First Table - help!

Quote:
Originally Posted by Kim View Post
Have I stumped you guys?
No, sorry, I've just been busy. Try this:
Code:
var numOfCols = 3;
var data = FusionPro.GetMultiLineRecords();

var table = new FPTable();
table.AddColumns(6000, 7000, 3000);

var header = table.AddRow();
header.Type = 'Header';
header.Cells[0].SetBorders('Thin', 'Black', 'Bottom');
header.CopyCells(0, 1);
header.SetContents('Date', 'Amount');


for (var i = 1; i <= data.recordCount; i++) {
  function ExField(str) { return TaggedTextFromRaw(data.GetFieldValue(i, str)); }

  // Skip this record if 'Date' & 'Amount' fields are both empty.
  var contents = ['Date', 'Amount'].map(ExField);
  if (!Trim(contents.join(''))) continue;
  var row = table.AddRow();
  row.SetContents.apply(row, contents);
}

// Determine how many columns are needed based on how many rows
// were added to the table (minus 1 for the header row).
var colsNeeded = table.Rows.length - 1;

// Number of rows needed to evenly distribute across numOfCols.
var rows = Math.ceil(colsNeeded / numOfCols);

// Duplicate column 1 and 2 (and their headers) to make up numOfCols.
for (var i = 0; i < (numOfCols - 1) * 3; i++) {
  table.Columns.push(table.Columns[i % 3]);
  table.Rows[0].Cells.push(table.Rows[0].Cells[i % 3])
}

// Concatenate the rows cells in order to reduce our total rows
// and fill up the extra columns.
var rowCounter = 1;
while (colsNeeded > rows) {
  var index = rowCounter % rows || rows;
  var row = table.Rows.splice(rows + 1, 1).pop();
  table.Rows[index].Cells = table.Rows[index].Cells.concat(row.Cells)
  rowCounter++
}

// Create reference variables to the cells of the first row (header)
// and second row (the date/amount values).
var [headerCells, contentCells] = table.Rows.slice(0, 2).map(function(s) { return s.Cells });

// We only need as many header cells as there are content cells. So, if
// there are more header cells than content cells, we can begin removing
// headers until the columns are equal.
while (headerCells.length > contentCells.length)
  headerCells.pop();

// Return the table tags.
return table.MakeTags();
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
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 11:19 AM.


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