ArcGIS JS中的地图打印功能本质上是调用GP服务,只不过这个GP已经在ArcGIS Server中封装好了,地图打印GP服务的过程是GP服务的异步调用,所以,地图输出功能实际上是在服务器端完成的,并且在arcgisserver目录下保存了处理结果。
调用ArcGIS API的Print实现地图的打印输出,部分代码如下:
//打印输出的参数数组,为打印输出的模板提供参数准备 var layouts = [{ name:"Letter ANSI A Landscape", label:"Landscape(PDF)", format:"pdf", options:{ "legendLayers":[legendlayer0,legendlayer1,legendLayer3], 'scalebarUnit':"Miles", 'titleText': dom.byId('print_title').value, "authorText":dom.byId('print_author').value, "copyrightText":dom.byId('print_copyright').value } },{ name:"Letter ANSI A Portrait", label:"Portrait(Image)", format:"jpg", options:{ "legendLayers":[legendlayer0,legendlayer1,legendLayer3], "scalebarUnit":"Miles", "titleText": dom.byId('print_title').value, "authorText":dom.byId('print_author').value, "copyrightText":dom.byId('print_copyright').value } }]; //定义打印输出的模板 var templates = array.map(layouts,function(lo){ var t = new PrintTemplate(); t.layout = lo.name; t.label = lo.label; t.format = lo.format; t.layoutOptions = lo.options; return t; }); //打印输出功能 printer = new Print({ map: map, templates:templates, url: "http://192.168.18.102:6080/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task" }, dom.byId("printButton")); printer.startup(); });
在浏览器端执行,输入图名、单位等信息并进行打印输出,选择打印的方式,如下:
遇到以下问题:
仔细查阅,打印的API中也并为提供对PrintTemplate的字体的设置,然而PrintTask服务也是调用了ArcGIS Server中内置的出图模板,找到目录,打开模板进行查看:
打开在代码中所使用的相应的模板进行查看,惊奇大发现:所有输出为乱码的图名、单位名称等在模板中的默认字体均为Arial欧洲字体
修改每一处的字体为中文字体
以图名为例,右键单击图名选址properties,点击Change Symbol,修改字体类型。修改完毕后保存并关闭MXD文档。如下:
再次执行