Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Spawning Multiple Templates using XObject

Explorer ,
Nov 23, 2020 Nov 23, 2020

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

 

TOPICS
Acrobat SDK and JavaScript
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 23, 2020 Nov 23, 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);
}

 

Translate
LEGEND ,
Nov 23, 2020 Nov 23, 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);
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 23, 2020 Nov 23, 2020

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2020 Nov 24, 2020

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 24, 2020 Nov 24, 2020

It should have a big effect since the page contents (text, images, vectors) of those 30 additional pages are not stored separately in the file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2020 Nov 24, 2020

If you use Save As after spawning it does the same, I believe.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 24, 2020 Nov 24, 2020

No, and it would be wrong if it did.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2020 Nov 24, 2020

Why want you 30 versions of the same pages?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 24, 2020 Nov 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! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2020 Nov 24, 2020

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 24, 2020 Nov 24, 2020
LATEST

It's an interactive journal - you write in it every day. Each day the user wants to write in their journal, they spawn a new writing template. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines