1

There are plenty of questions related to printing using ESRI's JS API, however, I am looking for a way to utilize a printer icon to automatically fire the task.

The samples show a print tool that uses a button with an arrow on one side to deliver a drop down of print templates to choose from. When you choose a template it then replaces the button with the word "Printout" that is a link to the print.

I would like something similar to the ArcGIS Online Web Map that has an icon that is clicked and a new window automatically pops up showing the print.

Any ideas?

1 Answer 1

4

I use this function in my website. I have a button labeled Print that calls this function.

function printMap(){
    var printMap = new esri.tasks.PrintTask("yourprintserverurl");
    var params = new esri.tasks.PrintParameters();
    var template = new esri.tasks.PrintTemplate();

    template.exportOptions = { dpi: 96};
    template.layout = "Letter ANSI A Portrait";
    template.preserveScale = true;
    template.showAttribution = false;

    template.layoutOptions = {
        legendLayers: [], // empty array means no legend
        scalebarUnit: "Feet",
        titleText: "PIN " + parcelPin,
        customTextElements: [
            {"physAddress" : printAddress},
            {"ownerOne" : ownerOne},
            {"ownerTwo" : ownerTwo},
            {"mailAddress" : mailAddress},
            {"mailCity" : mailCity},
            {"mailState" : mailState},
            {"mailZip" : mailZip},
            {"propReal" : propReal},
            {"calcAcre" : calcAcre},
            {"landVal" : landVal},
            {"buildVal" : buildVal},
            {"assessVal" : assessVal},
            {"marketVal" : marketVal}
        ]
    };

    params.map = map;
    params.template = template;
    printMap.execute(params, printResult);

    function printResult(result){
        console.log(result.url);
        window.open(result.url);
    };
};

I'm also passing values into my print template to display on the layout. The default output is png, but you can set the output type in the template parameters. Here is the API reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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