A_Poole13 Posted September 13, 2018 Share Posted September 13, 2018 I have a 4 page pdf that I need to loop through based on a field in the data and show the iteration of that loop as a variable on the page. Field = 5 show PDF Page 1, PDF Page 2, PDF Page 3, PDF Page 4, PDF Page 1 Field = 2 show PDF Page 1, PDF Page 2 Field = 7 show PDF Page 1, PDF Page 2, PDF Page 3, PDF Page 4, PDF Page 1, PDF Page 2, PDF Page 3 Thoughts? Quote Link to comment Share on other sites More sharing options...
A_Poole13 Posted September 13, 2018 Author Share Posted September 13, 2018 This is what I have so far. My thought process is that I need to loop through the field(Output) number. Example: field (Output) = 5. For every loop I need to show a specific page (1st loop - PageA, 2nd loop - PageB), if I get to the 4th loop, I need to set my counter to 1 so I pull PageA for the 5th loop because there are only 4 pages in my FusionPro document. I hope this is making sense. The code below is only giving me PageD for all records, which is incorrect so I am missing something. var PDFpages = "" var loopcount = 1 for (var pageLoop = 1; pageLoop <= Field("Output") ; pageLoop++) { if (loopcount = 1){ PDFpages += FusionPro.Composition.SetBodyPageUsage("PageA", true); PDFpages += FusionPro.Composition.SetBodyPageUsage("PageB", false); PDFpages += FusionPro.Composition.SetBodyPageUsage("PageC", false); PDFpages += FusionPro.Composition.SetBodyPageUsage("PageD", false); loopcount = 2; } else if (loopcount = 2){ PDFpages += FusionPro.Composition.SetBodyPageUsage("PageA", false); PDFpages += FusionPro.Composition.SetBodyPageUsage("PageB", true); PDFpages += FusionPro.Composition.SetBodyPageUsage("PageC", false); PDFpages += FusionPro.Composition.SetBodyPageUsage("PageD", false); loopcount = 3; } else if (loopcount = 3){ PDFpages += FusionPro.Composition.SetBodyPageUsage("PageA", false); PDFpages += FusionPro.Composition.SetBodyPageUsage("PageB", false); PDFpages += FusionPro.Composition.SetBodyPageUsage("PageC", true); PDFpages += FusionPro.Composition.SetBodyPageUsage("PageD", false); loopcount = 4; } else if (loopcount = 4){ PDFpages += FusionPro.Composition.SetBodyPageUsage("PageA", false); PDFpages += FusionPro.Composition.SetBodyPageUsage("PageB", false); PDFpages += FusionPro.Composition.SetBodyPageUsage("PageC", false); PDFpages += FusionPro.Composition.SetBodyPageUsage("PageD", true); loopcount = 1; } } return PDFpages; Quote Link to comment Share on other sites More sharing options...
ScottHillock Posted September 13, 2018 Share Posted September 13, 2018 This will work i think: for (i=1; i<=4; i++){FusionPro.Composition.SetBodyPageUsage(i, false);} FusionPro.Composition.repeatRecordCount = Field("Output"); var pageToCompose = FusionPro.Composition.repeatRecordNumber % 4; if (!pageToCompose){pageToCompose = 4;} FusionPro.Composition.SetBodyPageUsage(pageToCompose, true); FusionPro.Composition.AddVariable("iteration", Math.floor(((FusionPro.Composition.repeatRecordNumber - 1) / 4) + 1)); This will also give you a variable you can insert for the iteration number. Quote Link to comment Share on other sites More sharing options...
A_Poole13 Posted September 14, 2018 Author Share Posted September 14, 2018 This works beautifully! Thank you so much! 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.