Jump to content

Random pulls of static pages


Kal

Recommended Posts

Is there a way to pull random static pages.

 

I have a layout with 50 pages and pages named 1 to 50 in the "Page Usage"

Everyone gets Page1 & 2 then it's random and everyone gets the last 2 pages 49 & 50.

 

Static Pages 3 to 48 can be in any order like P3, 4, 5 or P4, 3, 47, 11, 5

 

I can have a data file created and populated with the pages that need to be pulled. Field called "VarPages"

 

How do I do this in "OnRecordStart"

 

Hope this is clear enough.

Link to comment
Share on other sites

You can't re-order pages in your template from OnRecordStart – you can only turn them on/off. Is that a requirement? If so, I would suggest having a 5 page template with pages 1, 2, 4, and 5 as static pages that always return pages 1, 2, 49 and 50 (respectively) and the 3rd page being an overflow page that adds a random number of pages, each pulling a different random page from the other 46 pages:

var pdf = CreateResource('path/to/your.pdf', 'graphic');
var pages = [];
for (var i=2; i<49; i++)
 pages.push(i);

return pages
 .sort(function(){
   return .5 - Math.random();
 })
 .splice(0, Math.floor((Math.random() * pages.length) + 1))
 .map(function(s){
   pdf.pagenumber = s;
   return pdf.content;
 })
 .join('<p>');

If you don't mind if they stay in order, you can variably turn random pages on and off like this:

for (var i=2; i<49; i++)
 if (Math.round(Math.random())) 
   FusionPro.Composition.SetBodyPageUsage(i, true);

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