Spawning Multiple Templates using XObject

Explorer ,
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

 

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

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

 

TOPICS
Acrobat SDK and JavaScript, General troubleshooting, How to, PDF forms

Views

52

Likes

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

Spawning Multiple Templates using XObject

Explorer ,
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

 

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

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

 

TOPICS
Acrobat SDK and JavaScript, General troubleshooting, How to, PDF forms

Views

53

Likes

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
Nov 23, 2020 0
Adobe Community Professional ,
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);
}

 

Likes

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
Reply
Loading...
Nov 23, 2020 0
Explorer ,
Nov 23, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Nov 23, 2020 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Nov 24, 2020 0
Adobe Community Professional ,
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.

Likes

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
Reply
Loading...
Nov 24, 2020 0
Most Valuable Participant ,
Nov 24, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Nov 24, 2020 0
Adobe Community Professional ,
Nov 24, 2020

Copy link to clipboard

Copied

No, and it would be wrong if it did.

Likes

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
Reply
Loading...
Nov 24, 2020 0
Adobe Community Professional ,
Nov 24, 2020

Copy link to clipboard

Copied

Why want you 30 versions of the same pages?

Likes

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
Reply
Loading...
Nov 24, 2020 0
Explorer ,
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! 

Likes

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
Reply
Loading...
Nov 24, 2020 0
Adobe Community Professional ,
Nov 24, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Nov 24, 2020 0
bev_s LATEST
Explorer ,
Nov 24, 2020

Copy link to clipboard

Copied

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. 

Likes

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
Reply
Loading...
Nov 24, 2020 0