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

Spawing 2 tamplates at same time (connected cells)

New Here ,
Oct 30, 2024 Oct 30, 2024

Copy link to clipboard

Copied

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

TOPICS
Al Assistant , Create PDFs , How to , JavaScript , PDF , PDF forms

Views

219

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 ,
Oct 30, 2024 Oct 30, 2024

Copy link to clipboard

Copied

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.

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
New Here ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

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

 

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 ,
Oct 30, 2024 Oct 30, 2024

Copy link to clipboard

Copied

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

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
New Here ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

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...

 

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 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

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.

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
New Here ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

Now I get it! I put this in one template (image field) and it works only if I generate new pages once. If I wanna add another ones they dont connect between. What I need to do to fix this?

 

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 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

Remove this from the script:

&& fieldName!=event.target.name

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
New Here ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

My code now looks like (bellow). And now don't copy image even in the first adding new page...

 

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.split(".").length!=1)
{
oFld.buttonSetIcon(event.target.buttonGetIcon()); break;
}
}

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 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

also remove break;

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
New Here ,
Nov 06, 2024 Nov 06, 2024

Copy link to clipboard

Copied

Now they connect. But they connect all new generated pages. I would like that when I generate new pages these 2 are linked to each other. Then I generate 2 new pages and only the most recent pages are linked to each other

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 06, 2024 Nov 06, 2024

Copy link to clipboard

Copied

Contact me privately and I'd be happy to provide you with a quote for this project.

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
New Here ,
Nov 07, 2024 Nov 07, 2024

Copy link to clipboard

Copied

LATEST

Now I have (below). It still needs a little finishing. The first pages it generates are great, because they are not connected to each other. Now, as far as I can see, it connects the 2nd sheet that is generated with the previous first sheet. For easier understanding, the document contains Slovenian and English versions or language. The code generates one sheet for the Slovenian language and one sheet for the English language. These two sheets must be connected to each other. which means that if I upload an image to one of these two pages, it must also appear on the other. Then I generate the data pages again, which means that it generates an additional sheet on the Slovenian version and an additional one on the English version. These newly generated sheets must be linked like the first one but must NOT be linked to the previous two (a different image is loaded).


// Import the icon for the current target field event.target.buttonImportIcon(); var aray = event.target.name.split("."); var fldName = aray[aray.length - 1]; var regex = new RegExp(fldName); // Track the two most recent pages where images are linked var lastLinkedPages = [this.numPages - 2, this.numPages - 1]; // Loop through all fields for (var i = 0; i < this.numFields; i++) { var fieldName = this.getNthFieldName(i); var oFld = this.getField(fieldName); // Check if the field is a button, matches the regex, and is on the most recent linked pages if ( oFld.type == "button" && regex.test(fieldName) && fieldName != event.target.name && fieldName.split(".").length != 1 && (oFld.page == lastLinkedPages[0] || oFld.page == lastLinkedPages[1]) ) { oFld.buttonSetIcon(event.target.buttonGetIcon()); } }

 

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