Skip to main content
bev_s
Inspiring
November 24, 2020
Resuelto

Spawning Multiple Templates using XObject

  • November 24, 2020
  • 10 respuestas
  • 1523 visualizaciones

I have two template pages that are spawned successfully 1 time each with this code I extracted from the SDK:

var a = this.templates;

   for (i = 0; i < a.length; i++)

      a[i].spawn(this.numPages, false, false);

 

Unfortunately the file size became rather large with multiple spawns, so I then tried to generate them as XObjects using the code also found in the SDK as it indicated it could reduce filesize; I tweaked the code below to only spawn one time by changing the 30 to a 1. 

   var t = this.templates;

   var T = t[0];

   var XO = T.spawn(this.numPages, false, false);

   for (var i=0; i<30; i++) T.spawn(this.numPages, false, false, XO);

 

The problem I am having is that it only recognizes one of my two templates and never spawns the second one. I have tried several different things -- all found on the internet and in the SDK as I'm quite the learner at this -- and have been completely unsuccessful. Any guidance on what I am doing incorrectly would be greatly appreciated - thank you!

 

Bev

 

Este tema ha sido cerrado para respuestas.
Mejor respuesta de George_Johnson

It's not entirely clear what you want to accomplish, but if you want to spawn template #1 and then template #2, and repeat that 30 more times, the code could be:

 

var aTemplates = this.templates;
var T1 = aTemplates[0];
var T2 = aTemplates[1];
   
var XO1 = T1.spawn(this.numPages, false, false);
var XO2 = T2.spawn(this.numPages, false, false);

for (var i = 0; i < 30; i++) {
    T1.spawn(this.numPages, false, false, XO1);
    T2.spawn(this.numPages, false, false, XO2);
}

 

10 respuestas

Bernd Alheit
Community Expert
Community Expert
November 24, 2020

Why want you 30 versions of the same pages?

bev_s
bev_sAutor
Inspiring
November 24, 2020

In my post, I indicated that I copied the code from the SDK, which was written to spawn one page 30x (you can ask them why they wanted 30 of the same page 😛 ) , but that I tweaked the code to only spawn one time, which was what I needed. I don't need 30 of the same page, but two pages spawned at a time. Eventually it would grow to total 60 pages, however, as it is an online journal in which a person spawns two pages per day for a month to write in their journal.

 

George's code worked perfectly and he is correct - in my testing of the code without using XObject, when I spawned all 60 pages, the file size was about 80MB; when I changed the code to use George's XObject code, the file size shrunk to 6.5MB. A big difference! 

Bernd Alheit
Community Expert
Community Expert
November 24, 2020

Why want you two pages per day with the same content?

Inspiring
November 24, 2020

It's not entirely clear what you want to accomplish, but if you want to spawn template #1 and then template #2, and repeat that 30 more times, the code could be:

 

var aTemplates = this.templates;
var T1 = aTemplates[0];
var T2 = aTemplates[1];
   
var XO1 = T1.spawn(this.numPages, false, false);
var XO2 = T2.spawn(this.numPages, false, false);

for (var i = 0; i < 30; i++) {
    T1.spawn(this.numPages, false, false, XO1);
    T2.spawn(this.numPages, false, false, XO2);
}

 

bev_s
bev_sAutor
Inspiring
November 24, 2020

That was exactly what I needed - thank you so much! ❤️

try67
Community Expert
Community Expert
November 24, 2020

This will have no effect on the file-size, though. It only makes the code work faster.