7

I'd like to create an option in my web application where a user can click on a print button and a list of options appears:

  1. Page template (already available via esri.dijit.print)
  2. Map Title
  3. Notes or Custom Text

No. 1 is known to be available but I can't find any good resource on how to be able to dynamically change these inputs. Any ideas?

Code I'm working with:

    dojo.require("esri.dijit.Print");

function initPrinter() {

    var printTemplates = [{
        label: "Map Only",
        format: "png32",
        layout: "MAP_ONLY",
        exportOptions: {
          width: map.width,
          height: map.height,
          dpi: 96
        }
      }, {
        label: "Portrait",
        format: "PDF",
        layout: "Letter ANSI A Portrait",
        layoutOptions: {
          titleText: "my layout",
          authorText: "GIS Team",
          copyrightText: "Copyright 2013",
          scalebarUnit: "Miles"
        }
        }, {
        label: "Landscape",
        format: "PDF",
        layout: "Letter ANSI A Landscape",
        layoutOptions: {
            titleText: "my layout",
            authorText: GIS Team",
            copyrightText: "Copyright 2013",
            scalebarUnit: "Miles"
            }
      }];

    // print dijit
    var printer = new esri.dijit.Print({
        map: map,
        templates: printTemplates,
        url: "path/to/my/Export%20Web%20Map%20Task"
        }, dojo.byId("printButtonDiv"));            

    printer.startup();

}
  • may be helpful for you gis.stackexchange.com/questions/17690/… – Sunil Mar 15 '13 at 16:14
  • I have print set up without any issues. My question is whether I can pass the parameters to the end user so they can define map template, map title and custom text vs me setting those via code. – Craig Mar 15 '13 at 16:28
5

Using this sample... http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/widget_print_esri_request.html

Instead of calling the request for printInfo and then handlePrintInfo on startup. Create some entry areas in your html where a user can enter values and a submit button. Setup an event handler for the onclick event of button.

After the onclick, then you call the handlePrintInfo and use the entry area values when you create the template. If you want, you could still get printInfo on startup, just save it to a variable outside init() so that it's ready for you.

// get print templates from the export web map task
function init() {
    var printInfo = esri.request({
      "url": app.printUrl,
      "content": { "f": "json" }
    });
    printInfo.then(handlePrintInfo, handleError);
}

function handlePrintInfo(resp) {...
| improve this answer | |
  • thanks. I'll give a try at this. I've attached my print.js code, its a bit different from the sample you linked to but I'm sure the idea is the same. – Craig Mar 15 '13 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.