创建打印任务

发送反馈


Web 打印服务默认开启异步打印模式。创建一个打印任务的步骤如下:

  1. 访问 iServer 服务列表,选择 webprinting/rest 服务资源
  2. 依次点击 webprinting -> v1 -> jobs,进入打印任务列表资源页面
  3. 点击创建打印任务,进入创建打印任务资源页面
  4. 输入 POST 请求体,点击“创建打印任务”按钮即可开始执行任务。关于请求体如何编写请参见 打印任务列表资源的 POST 请求

创建打印任务输入的请求体由三个顶层对象构成:

{

    "content": {},

    "layoutOptions": {},

    "exportOptions": {}

}

content

content 对象是必选对象,用于定义待打印的 Web 内容。由以下参数组成:

示例1:传入一个SuperMap iPortal 数据上图 Web App 制作的 WebMap 的 url 地址

{

    "content": {

        "type": "WEBMAP",

        "url":"http://supermapiportal:8190/iportal/web/maps/{mapid}/map.rjson"

     }

}

示例2:传入一个完整的 SuperMap iPortal 数据上图制作的 WebMap 的 json 表达

{

    "content": {

        "type": "WEBMAP",

        "value": {

            "extent": {

                "leftBottom": {

                    "x": -20037508.3427892,

                    "y": -20037508.3427891

                },

                "rightTop": {

                    "x": 20037508.3427892,

                    "y": 20037508.3427891

                }

            },

            "maxScale": "1:144447.927",

            "level": 4,

            "center": {

                "x": 11382417.9336122,

                "y": 4134167.44525748

            },

            "baseLayer": {

                "layerType": "TILE",

                "name": "ChinaDark",

                "url": "https://iserver.supermap.io/iserver/services/map-china400/rest/maps/ChinaDark"

            },

            "layers": [

                {

                    "layerType": "VECTOR",

                    "visible": true,

                    "name": "中国历史6级以上地震记录",

                    "featureType": "POINT",

                    "xyField": {

                        "xField": "经度",

                        "yField": "纬度"

                    },

                    "style": {

                        "fillColor": "#EE4D5A",

                        "strokeWidth": 1,

                        "offsetX": 0,

                        "offsetY": 0,

                        "fillOpacity": 0.9,

                        "radius": 8,

                        "strokeColor": "#ffffff",

                        "type": "BASIC_POINT",

                        "strokeOpacity": 1

                    },

                    "projection": "EPSG:4326",

                    "enableFields": [

                        "年",

                        "月",

                        "日",

                        "时",

                        "分",

                        "秒",

                        "经度",

                        "纬度",

                        "深度",

                        "震级",

                        "震级类型",

                        "参考地名"

                    ],

                    "dataSource": {

                        "name": "ChinaRecordOfOver6Earthquakes",

                        "type": "SAMPLE_DATA"

                    }

                }

            ],

            "description": "",

            "projection": "EPSG:3857",

            "minScale": "1:591658710.909",

            "title": "testdizhen",

            "version": "2.2.1",

            "rootUrl": "https://iptl.supermap.io/iportal/services/../"

        }

    }

}

layoutOptions

layoutOptions 对象是必选对象,用于定义打印的布局信息。由以下参数组成:

    计算参数:

    整饰参数:

示例1:更新布局模板、更新布局中指北针的图片为 url 地址、更新小地图为一个 WebMap 图层、更新图例为一个 JSON 字符串

{

    "layoutOptions": {

        "templateName": "A4_landscape",

        "title": "title",

        "author": "authorName",

        "copyright": "copyright",

        "subTitle": "subTitle",

        "legendOptions": {

            "title": "legend",

            "customItems": [

                {

                    "name": "Railway",

                    "picAsUrl":

                        "http://192.168.120.40:8090/iserver/services/map-China100/rest/maps/China/layers/Main_Railway_L@China@@China/legend"

                },

                {

                    "name": "River",

                    "picAsUrl":

                        "http://192.168.120.40:8090/iserver/services/map-China100/rest/maps/China/layers/River@China@@China/legend"

                },

                {

                    "name": "Mainroad",

                    "picAsUrl":

                        "http://192.168.120.40:8090/iserver/services/map-China100/rest/maps/China/layers/Main_Road_L@China@@China/legend"

                },

                {

                    "name": "Airport",

                    "picAsUrl":

                        "http://192.168.120.40:8090/iserver/services/map-China100/rest/maps/China/layers/Airport_pt@China.1@@China/legend"

                }

            ]

        },

        "northArrowOptions": {

            "picAsUrl": "file://NorthArrow.svg"

        },

        "littleMapOptions": {

            "center": {

                "x": 12024583.8595938,

                "y": 4101942.08146721

            },

            "scale": 5.4085234291297E-08,

            "layers": [

                {

                    "layerType": "TILE",

                    "name": "China",

                    "url": "http://192.168.120.40:8090/iserver/services/map-China100/rest/maps/China"

                }

            ]

        }

    }

}

exportOptions

exportOptions 对象是必选对象,用于定义打印的输出信息,由以下参数组成:

示例:更新打印输出的格式为 PDF、打印的 dpi 为300dpi

{

    "exportOptions": {

        "format": "PDF",

        "dpi": 300,

        "center": {

            "x": 100,

            "y": -10

        },

        "scale": 0.0001

    }

}

图例元素自动排版规则

iServer Web 打印服务为用户提供了图例元素自动排版规则。当 Web 打印布局中的图例元素包含多个图例子项时,无需手动调整图例子项的字号、边距等参数,系统即可自动排版。

图例元素自动排版功能当前依照图例子项全部显示的规则,具体参数及设置方法参见:layoutOptions,具体规则如下: