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

Spawning Multiple Templates using XObject

Explorer ,
Nov 23, 2020 Nov 23, 2020

Copy link to clipboard

Copied

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

Views

811

Translate

Translate

Report

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);
}

 

Votes

Translate

Translate
LEGEND ,
Nov 23, 2020 Nov 23, 2020

Copy link to clipboard

Copied

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);
}

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

No, and it would be wrong if it did.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Why want you 30 versions of the same pages?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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! 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

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