AnsweredAssumed Answered

printTemplate - customTextElememts

Question asked by schlot on Jun 5, 2013
Latest reply on Jun 5, 2014 by mvolz47
I have created a custom print service, but I'm a little confused on the syntax for adding custom text elements. I added two additional pieces of text and gave them element names of subTitleText and descripText.

I added these into my printTemplate definition.  I also need to change the values dynamically.  From other thread, I got the syntax for changing the title by doing a dojo.connect on the printer's "onPrintStart" event. I've attempted to add a few more lines to populate the custom text elements in a similar way. 

I have print dijit in a floating pane, but I think that part is OK.  I could generate output when I was using the original out of the box webmaptemplates. 
    //functions for printing     function openPrint(){         var layoutTemplate, templateNames, mapOnlyIndex;         var fp = dijit.byId('floater_print');         if ((fp.style == "visibility: hidden;") || (fp.style = "VISIBILITY:hidden;")) {             fp.style.visibility = "visible";             fp.show();         }     }     function setupPrinting(subHeaderTitle){      //   var layoutTemplate, templateNames, mapOnlyIndex;                  // create an array of objects that will be used to create print templates         // create an array of objects that will be used to create print templates         var layouts = [{             "name": "customExport_FMDC_Landscape",             "label": "Landscape - PDF",             "format": "pdf",             "options": {                 "legendLayers": [], // empty array means no legend                 "scalebarUnit": "Miles",                 "titleText": subHeaderTitle,                 "customTextElements": {                     "descripText": fullLegalString,                      "subTitleText": subHeaderTitle }                        }         }                ,{             "name": "customExport_FMDC_Landscape",             "label": "Portrait do not use",             "format": "pdf",             "options": {                 "legendLayers": [], // empty array means no legend                 "scalebarUnit": "Miles",                 "titleText": subHeaderTitle,                 "customTextElements": {                     "descripText": fullLegalString,                      "subTitleText": subHeaderTitle }                        }          }         ];                  // create the print templates, could also use dojo.map         dojo.forEach(layouts, function(lo){             var t = new esri.tasks.PrintTemplate();             t.layout = lo.name;             t.label = lo.label;             t.format = lo.format;             t.layoutOptions = lo.options;             templates.push(t);         });                  var printer = new esri.dijit.Print({             "map": map,             "templates": templates,             url: printUrl         }, dojo.byId("PrintDiv2"));                  printer.startup();         dojo.connect(printer, "onPrintStart", function(){             var printTitle = dojo.byId("txtTitle").value;             for (var i = 0; i < templates.length; i++) {                 this.templates[i].layoutOptions.titleText = printTitle;                 this.templates[i].layoutOptions.customTextElements.descripText = fullLegalString;                 this.templates[i].layoutOptions.customTextElements.subTitleText = print_subTitle;                // this.templates[i].layoutOptions.customTextElements[0] = fullLegalString;               //  this.templates[i].layoutOptions.subTitleText = print_subTitle;                 console.log("onPrintStart: fullLegalString = " + fullLegalString + "print_subTitle = " + print_subTitle);             }          });     }


When I run this, I get one of those syntax errors that you can't ever figure out what it goes with.  I can see the POST call in Firebug.  If I copy the entire JSON statement and paste it into the print service rest endpoint, it does generate output.  But it doesn't have my custom elements.  I'm wondering if it's because I'm not using the right syntax when I'm defining these within my layoutOptions.

Outcomes