Skip to main content
Participating Frequently
October 30, 2024
Question

Spawing 2 tamplates at same time (connected cells)

  • October 30, 2024
  • 2 replies
  • 1071 views

As you can see, the code (under) generates two pages in different places. I need these two generated pages to have connected windows for adding images (you upload an image in one window and it also appears in the other) (name: P2.Template2.P1.Template.P2.Template.P1.Template.Image25 ). Above the images is another box with text that must not be linked (name:P2.Template2.P1.Template.P2.Template.P1.Template.Text22). These states are generated from the template, so if a new request for generation is added, i.e. 2 additional pages, these two pages must not be linked to the previously generated 2 pages. To repeat, I have a 4-page document that has an interactive button to generate new pages (when clicked, it generates 2 new pages that go to a specific location (code above that doesn't change)). When generating this I want the document to have 6 pages of which 4 pages will be text and images, but the box on sheet 2 and 4 should only be associated with images and not text. the windows on pages 3 and 6 must also be connected. Pages 2 and 3 or 4 and 6 must not be connected to each other

 

if (typeof lastPageForTemplate2 === 'undefined') {
var lastPageForTemplate2 = 2;
} else {
lastPageForTemplate2 += 1;}

this.getTemplate("Template2").spawn({ nPage: lastPageForTemplate2, bRename: true, bOverlay: false });

var totalNumberOfPages = this.numPages;this.getTemplate("Template4").spawn({ nPage: totalNumberOfPages, bRename: true, bOverlay: false });

this.calculateNow();;

This topic has been closed for replies.

2 replies

PDF Automation Station
Community Expert
Community Expert
October 30, 2024

Judging by the field name  "P2.Template2.P1.Template.P2.Template.P1.Template.Image25" it looks like you might have used a spawned template page to create another template.  Regardless, assuming you want the button image to copy to the corresponding button image on another spawned page after the page has already been spawned and the user clicks the button to insert the image, you could use the following mouse up action on all of the buttons (image fields are button fields with a script) that extracts the last part of the field name after the last period, loops through all the fields, tests whether they are button fields, excludes the field containing the script, tests whether their names contain the extracted portion, and finally, test whether their names are not ONLY the extracted portion.  Fields that pass will display the icon of the field the user clicked:

 

event.target.buttonImportIcon();
var aray=event.target.name.split(".");
var fldName=aray[aray.length-1];
var regex=new RegExp(fldName);
for(var i=0;i<this.numFields;i++)
{
var fieldName=this.getNthFieldName(i);
var oFld=this.getField(fieldName);
if(oFld.type=="button" && regex.test(fieldName) && 
fieldName!=event.target.name && fieldName.split(".").length!=1)
{
oFld.buttonSetIcon(event.target.buttonGetIcon()); break;
}
}
3785Author
Participating Frequently
November 4, 2024

I try with this code but don't work... If I use it with old code they generate me 4 new pages and open the window to upload picture and after that I try to upload picture and don't show it in document...

 

PDF Automation Station
Community Expert
Community Expert
November 4, 2024

The code has nothing to do with generating pages.  It is mouse up action for an image button to copy to the image to other buttons that contain the same root name as the button being clicked.  I should replace event.target.buttonImportIcon() as a mouse up action in the button fields.

try67
Community Expert
Community Expert
October 30, 2024

They can't be connected automatically, since they will have unique field names (even if the original names are the same, since they are renamed when spawned). You will need to write a script to copy the selected image from the first field to the second one, taking into account the new names they will have on the spawned pages.

3785Author
Participating Frequently
November 4, 2024

How I can make this? Do you have any code or something?