Adding print pages

I have a COTG document where users can add additional pages and draw on them. Created a script to add the additional pages. Which it does complete with overlaying the correct image on top. But it also adds an additional copy of the page without the image. Does the same with every additional page

not seeing where it’s coming from. Here is the script

   var numPage2 = record.tables.detailPage1.length;
   var printSections = merge.template.contexts.Print.sections;

   if( numPage2 > 1)  //there is always a first page
    {
	for( var i = 1; i < numPage2; i++)
	 {
	   var image = record.tables.detailPage1[i].fields["image_annotation1-note-data"];
	   var clone = printSections["Page2"].clone();
       var clone.name = "Page2-"+i;
	   clone.html("<br><br>" + image)  //image holds annotation
	   clone.enabled = true;
	   printSections["Page2"].addAfter(clone);
	 }  
   }

Anyone see where I went wrong ?

Jerry

If you remove the cloning script, does the section display 1 or 2 pages? If it displays 2, each clone will do so as well.

If that’s not the issue, then try commenting out the clone.html("<br><br>" + image) statement in your script: it might trigger an overflow, which would account for the second page on each clone.

If I comment out the clone.html line I get two copies of the page with the first page image and not the third page. Also noticed on the original one the second and third pages have red dotted lines at the bottom

image

Looks like it’s how I’m adding the image on to subsequent pages

It was related to the image, thanks for pointing me in that direction. Modified my script.

var numPage2 = record.tables.detailPage1.length;
  
var background = 'Images/Standard Measure New 2019page2.pdf';
var printSections = merge.template.contexts.Print.sections;

//merge.template.contexts.Print.sections["Page2"].enabled = false;
if( numPage2 > 1)
{
	for( var i = 1; i < numPage2; i++)
	{
 	  var image = record.tables.detailPage1[i].fields["image_annotation1-note-data"];
 	  var clone = printSections["Page2"].clone();
      var line1 = '<p> <br> </p>';
      var line2 = '<div anchor="page_media_0"';
      var line3 =  'style="position: absolute; overflow: hidden; box-sizing: border-box; width: 816px; height: 1056px; top: -48.0333px; left: -48.0333px;"';
      var line4 = ' offset-x="-0.033299999999997" offset-y="-0.033299999999997">';
      var line5 = '<span>' + image + '</span> </div>'
      var imageHTML = line1.concat(line2,line3,line4,line5);
     clone.name = "Page2-"+i;
     clone.html(imageHTML);
	 clone.enabled = true;
	 printSections["Page2"].addAfter(clone);
	
	}  
 
}

Proably not the best way to do it :slight_smile:, it’s the first iteration and it works. I’ll work on it more later on