configuration.rst 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. Configuration
  2. *************
  3. The server side uses a `YAML <http://www.yaml.org/>`_ configuration file that defines the page layouts and allowed values. This file is usually called config.yaml.
  4. .. note:: Warranty disclaimer and license
  5. The authors provide these documents "AS-IS", without warranty of any kind
  6. either expressed or implied.
  7. Document under `Creative Common License Attribution-Share Alike 2.5 Generic
  8. <http://creativecommons.org/licenses/by-sa/2.5/>`_.
  9. Authors: MapFish developers.
  10. General structure
  11. -----------------
  12. Here is the general structure:
  13. .. code-block:: yaml
  14. dpis:
  15. - 254
  16. - 190
  17. {...}
  18. ?maxSvgWidth: 2048 # set the maximum dimensions to 2048 points, this is useful when using MapServer and a maximum dimension is there
  19. ?maxSvgHeight: 2048
  20. ?integerSvg: false # the library in MapServer <= 5.6 does not support floating point values in the SVG coordinate space, set this to true if using a WMS that does not support floating point values in SVG coordinates
  21. ?ignoreCapabilities: false # assume client is correct and do not load capabilities. This is not recommended to be used unless you it fails when false (false is default)
  22. ?disableLayersMerging: false # WMS layers with mergable parameters will be merged by default. Set this to true to disable attempts to merge.
  23. ?maxPrintTimeBeforeWarningInSeconds: 30 # if print jobs take longer than this then a warning in the logs will be written along with the spec.
  24. ?printTimeoutMinutes: 5 # The maximum time to allow a print job to take before cancelling the print job. The default is 5 (minutes)
  25. ?formats:
  26. - pdf
  27. - png
  28. {...}
  29. scales:
  30. - 25000
  31. - 50000
  32. {...}
  33. hosts:
  34. - {HOST_WHITELIST_DEFINITION}
  35. {...}
  36. ?localHostForward: # For request on map.example.com we build an http request on localhost with the header Host=map.example.com, this is to don't pass throw the proxy.
  37. ? from:
  38. ? - map.example.com
  39. ? https2http: True # For above hosts on request on https we build a request on http
  40. ?headers: ['Cookie', 'Referer'] # The header that will be copyed to the tiles http requests
  41. ?keys:
  42. ? - !key
  43. ? host: !dnsMatch
  44. ? host: maps.google.com
  45. ? port: 80
  46. ? domain: !dnsMatch
  47. ? host: localhost
  48. ? key: 1234456
  49. ? id: gmd-xyz
  50. ?fonts:
  51. ? - {PATH}
  52. ?globalParallelFetches: 5
  53. ?perHostParallelFetches: 5
  54. ?tilecacheMerging: false
  55. ?connectionTimeout: 30000 MF_V1.2
  56. ?socketTimeout: 180000 MF_V1.2
  57. ?outputFilename: Mapfish-print MF_V1.2
  58. ?disableScaleLocking: false
  59. ?brokenUrlPlaceholder: default MF_V2.0
  60. ?proxyBaseUrl: http://mapfishprint.org MF_V2.0
  61. ?tmsDefaultOriginX: 0.0f MF_V2.0
  62. ?tmsDefaultOriginY: 0.0f MF_V2.0
  63. ?security:
  64. ? - !basicAuth
  65. ? matcher: !dnsMatch
  66. ? host: www.camptocamp.com
  67. ? post: 443
  68. ? username: xyz
  69. ? password: zyx
  70. ? preemptive: true
  71. ? - !basicAuth
  72. ? username: abc
  73. ? password: bca
  74. layouts:
  75. {LAYOUT_NAME}:
  76. ? : Mapfish-print.pdf MF_V1.2
  77. ? metaData:
  78. ? {METADATA_DEFINITION}
  79. ? titlePage:
  80. ? {PAGE_DEFINITION}
  81. mainPage:
  82. ? rotation: false
  83. {PAGE_DEFINITION}
  84. ? lastPage:
  85. ? {PAGE_DEFINITION}
  86. {...}
  87. Optional parts are shown with a question mark in the left margin. The question marks must not be put in the configuration file. Their default values is shown.
  88. Note: Sets of values like DPI can be entered in one of two forms:
  89. .. code-block:: yaml
  90. dpi: [1,2,3,...]
  91. or
  92. .. code-block:: yaml
  93. dpis:
  94. - 254
  95. - 190
  96. DPI and PDF Dimensions
  97. ^^^^^^^^^^^^^^^^^^^^^^
  98. A chosen DPI value from the above configuration is used in WMS GetMap requests as an added format_options (GeoServer) or map_resolution (MapServer) parameter. This is used for symbol/label-rescaling suitable for high resolution printouts, see `Geoserver format_options specification <https://docs.geoserver.org/stable/en/user/services/wms/vendor.html>`_ (Geoserver 2.1) and `MapServer defresolution keyword <http://mapserver.org/development/rfc/ms-rfc-55.html>`_ (MapServer 5.6) for more information.
  99. In general, PDF dimensions and positions are specified in points. 72 points == 1 inch == 25.4 mm.
  100. Getting Maps
  101. ^^^^^^^^^^^^
  102. The list of {HOST_WHITELIST_DEFINITION} defines the allowed URLs for getting maps. Its format will be defined in `the next sub-section <configuration.html#host-whitelist-definition>`_.
  103. The formats element lists the values formats that the server permits.
  104. * If omitted only 'pdf' is permitted.
  105. * If the single element '*' (quotes are required) is present then all formats that the server can produce can be requested.
  106. The formats the server can produce depends to a large degree on how the Java is configured.
  107. PDF is supported on all systems but for image output formats JAI and ImageIO is used which means both must be on the server for them to be available. You can get the list of supported formats by running the standalone client with the `--clientConfig` flag enabled (you will need to supply a yaml config file as well). If you are using the servlet then do a get info request to see the list of formats (with the '*' as the outputFormats parameter in the config file).
  108. "globalParallelFetches" and "perHostParallelFetches" are used to tune the parallel loading of the map tiles/images. If you want to disable the parallel loading, set "globalParallelFetches" to 1.
  109. New versions of tilecache added the support for merging multiple layers in a single WMS request. If you want to use this functionality, set the "tilecacheMerging" attribute to true.
  110. "connectionTimeout" and "socketTimeout" can be used to tune the timeouts for reading tiles from map servers.
  111. "proxyBaseUrl" the optional url of the proxy between mapfish-print and the internet. This is the url base that will be in the info.json response. On occasion the url or port of the web server containing mapfish-print is not the server that is public to the internet and the requests are proxied to the mapfish-print webserver. In this case it is important for the info.json request to return the public URL instead of the url of the webserver.
  112. "tmsDefaultOriginX" By default this is null. If non-null then TmsMapReader will use this as the origin x value if null then the origin will be derived from the maxExtent parameter.
  113. "tmsDefaultOriginY" By default this is null. If non-null then TmsMapReader will use this as the origin y value if null then the origin will be derived from the maxExtent parameter.
  114. Layouts
  115. ^^^^^^^
  116. You can have as many layouts as you want. Their name must be unique and will be used on the client side.
  117. A layout can have a "titlePage" that will be added at the beginning of the generated document. It cannot contain any map.
  118. The "mainPage" section is mandatory and will be used once for each page requested. The details of a {PAGE_DEFINITION} section can be found `in another sub-section of this document <configuration.html#page-definition>`_.
  119. A layout "lastPage", will be added for the end of the document, and cannot contain any map.
  120. If you want to let the user rotate the map (for a given layout), you have to set the "rotate" field to "true" in the corresponding "mainPage" section.
  121. Output filename
  122. ^^^^^^^^^^^^^^^
  123. If the 'outputFilename' parameter is defined in the main body then that name will be used by the MapPrintServlet when sending the pdf to the client. It will be the name of the file that the client downloads. If the 'outputFilename' parameter is defined in a layout then that value will override the default name. In both cases the `.pdf` suffic is optional; if not present the server will append `.pdf` to the name.
  124. In all cases the `json` request can override the filename defined in the configuration file by posting a 'outputFilename' attribute in the posted JSON. If the outputFilename has ${date}, ${time} or ${dateTime} in it, it will be replaced with the current date using the related DateFormat.get*Instance().format() method. If a pattern is provided it will be passed to SimpleDataFormat for processing. A few examples follow:
  125. * outputFilename: "host-${yyyyMMdd}.pdf" # results in host-20111213.pdf
  126. * outputFilename: "host-${date}" # results in host-Dec_13_2011.pdf (actual output depends on local of server)
  127. * outputFilename: "host-${dateTime}" # results in host-Dec_13_2011_1:10:50_PM.pdf (actual output depends on local of server)
  128. * outputFilename: "host-${time}.pdf" # results in host-1:11:14_PM.pdf (actual output depends on local of server)
  129. * outputFilename: "host-${yyMMdd-hhmmss}"# results in host-111213-011154.pdf (actual output depends on local of server)
  130. "disableScaleLocking" allows you to bypass the choosing of scale from the available factors, and simply use the suggested value produced inside MapBlock.java.
  131. Broken images
  132. ^^^^^^^^^^^^^
  133. "brokenUrlPlaceholder" the placeholder image to use in the case of a broken url. By default, when a url request fails, an error is thrown and the pdf process terminates. However if this parameter is set then instead a placeholder image is returned.
  134. Non-null values are:
  135. * "default" - use the system default image.
  136. * "throw" - throw an exception.
  137. * <url> - obtain the image from the supplied url. If this url is broken then an exception will be thrown. This can be anytype of valid url from a file url to https url.
  138. Security
  139. --------
  140. Both Keys and Security are options for accessing protected services. Keys are currently for Google maps premium accounts and Security is for other types and is more general Currently only BasicAuth is supported but other strategies can easily be added
  141. .. code-block:: yaml
  142. security:
  143. - !basicAuth
  144. matcher: !dnsMatch
  145. host: www.camptocamp.com
  146. post: 443
  147. username: xyz
  148. password: zyx
  149. preemptive: true
  150. - !basicAuth
  151. username: abc
  152. password: cba
  153. The above example has 2 security configuration. Each option is tested (in order) to see if it can be used for the given URI and if it applies it is used to configure requests for the URI. In the above example the first configuration will be used if the URI matches the hostmatcher provided if not then the second configuration will be applied. The last configuration has no host matcher so it is applied to all URIs.
  154. A basicAuth security configuration consists of 4 options
  155. * matcher - a host matcher for determining which requests need the security to be applied
  156. * username - username for basicauth
  157. * password - password for basicauth
  158. * preemptive - optional, but for cases where the credentials need to be sent without the challenge
  159. X Forwarded For
  160. ^^^^^^^^^^^^^^^
  161. Added ``addForwardedFor`` optional flag (``true`` / ``false``) to enable by IP security.
  162. When the option is ``true``, every request to WMS services have an ``X-Forwarded-For`` header with the client IP / name, so that IP based security rules are correctly applied by the underlying service.
  163. Keys
  164. ----
  165. Google maps currently requires a private key to be used (we only support users Google maps premium accounts).
  166. The keys section allows a key to be mapped to hosts. The hosts are identified with host matchers that are described in the <configuration.html#host-whitelist-definition> sub-section.
  167. In addition a domain hostmatcher can be used to select a key based on the domain of the local server. This can be useful if the same configuration is used in a test environment and a production environment with differing domains. For example mapfish.org and mapfish.net.
  168. Finally google maps (for example) requires a client id as well that is associated with the private key. There for in the case of google premium services a legal key would be:
  169. .. code-block:: yaml
  170. keys:
  171. - !key
  172. key: yxcvyxvcyxvyx
  173. id: gme-xxxcs
  174. Thanks to the hosts and domain matcher it is possible to have a key for google maps and (for future proofing) a different key for a different service.
  175. Fonts definition
  176. -----------------
  177. The "fonts" section is optional. It contains the path of the fonts you want to use. The entries can point to files (TTF, OTF, TTC, AFM, PFM) or directories. Don't point to directories containing too many files since it will slow down the start time. By default, PDF gives you access to the following fonts (Cp1252 encoding only):
  178. * Courrier (-Bold, -Oblique, -BoldOblique)
  179. * Helvetica (-Bold, -Oblique, -BoldOblique)
  180. * Times (-Roman, -Bold, -Oblique, -BoldOblique)
  181. * Symbol
  182. * ZapfDingbats
  183. Host whitelist definition
  184. -------------------------
  185. In this section, you can put as many entries as you want, even for the same type of filter. If at least one matches, the Map server can be used.
  186. This section is not for defining which client can request maps. It is just here to avoid having the print module used as a proxy to access documents from computers behind firewalls.
  187. There are 3 ways to whitelist a host.
  188. Allowing every local services:
  189. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  190. .. code-block:: yaml
  191. - !localMatch
  192. dummy: true
  193. The "dummy" parameter is ignored, but mandatory to avoid a limitation in the YAML format.
  194. Allowing by DNS name:
  195. ^^^^^^^^^^^^^^^^^^^^^
  196. .. code-block:: yaml
  197. - !dnsMatch
  198. host: labs.metacarta.com
  199. Allowing by IP address:
  200. ^^^^^^^^^^^^^^^^^^^^^^^
  201. .. code-block:: yaml
  202. - !ipMatch
  203. ip: www.camptocamp.org
  204. ? mask: 255.255.255.255
  205. The "ip" parameter can be a DNS name that will be resolved or directly an IP address.
  206. All the methods accept the following optional parameters:
  207. * port: to limit to a certain TCP port
  208. * pathRegexp: a regexp that must match the path part of the URL (before the '?').
  209. Metadata definition
  210. -------------------
  211. Allow to add some metadata to the generated PDF. They are visible in acroread in the File->Properties menu.
  212. The structure is like that:
  213. .. code-block:: yaml
  214. metaData:
  215. ? title: ''
  216. ? author: ''
  217. ? subject: ''
  218. ? keywords: ''
  219. ? creator: ''
  220. ? supportLegacyReader: false
  221. All fields are optional and can use global variables, as defined in the `Block definition <configuration.html#block-definition>`_ chapter. Page specific variables are not accessible.
  222. Page definition
  223. ---------------
  224. The structure is like that:
  225. .. code-block:: yaml
  226. pageSize: A4
  227. ? landscape: false
  228. ? marginLeft: 40
  229. ? marginRight: 40
  230. ? marginTop: 20
  231. ? marginBottom: 20
  232. ? backgroundPdf: template.pdf
  233. ? condition: null
  234. ? header:
  235. height: 50
  236. items:
  237. - {BLOCK_DEFINITION}
  238. {...}
  239. items:
  240. - {BLOCK_DEFINITION}
  241. {...}
  242. ? footer:
  243. height: 50
  244. items:
  245. - {BLOCK_DEFINITION}
  246. {...}
  247. ? includeTitlePage: true
  248. ? includeLastPage: true
  249. ? includeExtraPage: true
  250. With the "condition" we can completely hide a page, same behavior than in block.
  251. If "backgroundPdf" is specified, the first page of the given PDF file will be added as background of every page.
  252. The "header" and "footer" sections are optional. If the "items" that are in the main section are too big, more pages are generated. The header and footer will be drawn on those pages as well.
  253. Here is a short list of supported **pageSizes**:
  254. +--------+-------+--------+
  255. + name + width + height +
  256. +========+=======+========+
  257. + LETTER + 612 + 792 +
  258. +--------+-------+--------+
  259. + LEGAL + 612 + 1008 +
  260. +--------+-------+--------+
  261. + A4 + 595 + 842 +
  262. +--------+-------+--------+
  263. + A3 + 842 + 1191 +
  264. +--------+-------+--------+
  265. The complete list can be found in http://api.itextpdf.com/itext/com/itextpdf/text/PageSize.html. If you want to use a custom page size, you can set **pageSize** to the width and the height separated by a space.
  266. Skip Rendering Of Pages
  267. ^^^^^^^^^^^^^^^^^^^^^^^
  268. New flag params to skip rendering of particular pages have been implemented:
  269. * `includeTitlePage`
  270. * `includeLastPage`
  271. * `includeExtraPage`
  272. They are all defaulted to true.
  273. Extra Pages
  274. ^^^^^^^^^^^
  275. Additional Pages are supported in many different places. They can be rendered due to legends overflowing on multiple pages, or by the dynamic images functionality.
  276. Where additional pages can be generated, the generating block will be spread among all the created pages (for example, the legend block will put legends on different pages, if configured to do so). If you want to put additional blocks on additional page, you can specify the `renderOnExtraPage` flag on the desired blocks. Only first level blocks are considered.
  277. In addition to that, an explicit `extraPage` block can be used in :file:`config.yaml` to add a custom page between other pages. The `renderOn` property specify the exact position for rendering (`beforeMainPage`, `beforeLastPage` or `afterLastPage`).
  278. Block definition
  279. ----------------
  280. The next sub-sections document the possible types of blocks.
  281. In general, text values or URLs can contain values taken from the **spec** structure coming with the client's request. A syntax similar to shell is used: `${variableName}`. If the current page is a **titlePage**, only the root values are taken. If it's a **mainPage**, the service will first look in the current **page** section then in the root values. Here is how to use this functionality::
  282. text: 'The value of mapTitle is: ${mapTitle}'
  283. Some virtual variables can be used:
  284. * ${pageNum}: The current page number.
  285. * ${pageTot}: The total number of pages. Can be used only in text blocks.
  286. * ${now}: The current date and time as defined by the machine's locale.
  287. * ${now FORMAT}: The current date and time as defined by the FORMAT string. The syntax is here: http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html.
  288. * ${configDir}: The absolute path to the directory of the configuration file.
  289. * ${format PRINTF VAR}: Format the value of VAR using the provided `PRINTF format <http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#syntax>`_ (for example: %,d).
  290. All the blocks can have a condition attribute that takes a spec attribute name. If the attribute name exists and is not equal to "false" or "0", the block is drawn. Otherwise, it is ignored. An exclamation mark may precede the condition to invert it, exclamation mark is part of yaml syntax, than the expression should be in quotes.
  291. Example: show text block only if in the spec the attribute name "showText" is given, is not equal to "false" and not equal to "0":
  292. .. code-block:: yaml
  293. - !text
  294. text: 'mytext'
  295. condition: showText
  296. Text block
  297. ----------
  298. .. code-block:: yaml
  299. - !text
  300. ? font: Helvetica
  301. ? fontSize: 12
  302. ? fontEncoding: Cp1252
  303. ? fontColor: black
  304. ? spacingAfter: 0
  305. ? align: left
  306. ? vertAlign: middle
  307. ? backgroundColor: #FFFFFF
  308. text: 'Blahblah'
  309. ? asHTML: false
  310. Typical "fontEncoding" values are:
  311. * Cp1250
  312. * Cp1252
  313. * Cp1257
  314. * Identity-H (horizontal UTF-8)
  315. * Identity-V (vertical UTF-8)
  316. * MacRoman
  317. The "font" must refer to a standard PDF font or a `declared font <configuration.html#fonts-definition>`_.
  318. HTML In Text Blocks
  319. ^^^^^^^^^^^^^^^^^^^
  320. The new configuration property `asHTML` (to be used in :file:`config.yaml` text blocks) allows to automatically render the included text as HTML (when true), instead of simple text. HTML tags are interpreted and styled.
  321. Image block
  322. -----------
  323. .. code-block:: yaml
  324. - !image
  325. maxWidth: 200
  326. maxHeight: 100
  327. ? spacingAfter: 0
  328. ? align: left
  329. ? vertAlign: middle
  330. url: http://trac.mapfish.org/trac/mapfish/chrome/site/img/mapfish.png
  331. Supported formats are PNG, GIF, Jpeg, Jpeg2000, BMP, WMF (vector), SVG and TIFF.
  332. The original aspect ratio will be respected. The url can contain "${}" variables.
  333. Simple colored box icons
  334. ^^^^^^^^^^^^^^^^^^^^^^^^
  335. This enhancement adds the feature of drawing a simple colored box, instead of an icon into a legend item.
  336. To draw a colored box, include a color: #hexvalue property in the printing spec, instead of an icon: url property.
  337. Base64
  338. ^^^^^^
  339. We added support for Base64 encoded images uris to PDFUtils so that embedded images can be included for styling vector points (for example).
  340. Example url:
  341. .. code-block:: yaml
  342. url: data:image/png;base64,<encoded image>
  343. Images content
  344. ^^^^^^^^^^^^^^
  345. This enhancement allow you add SVG content inside the specification of the print.
  346. You need to add a name into the image to manage:
  347. .. code-block:: yaml
  348. - !columns
  349. width: 580
  350. height: 271
  351. absoluteX:70
  352. absoluteY:400
  353. items:
  354. - !image
  355. name: chart1
  356. maxWidth: 580
  357. maxHeight: 271
  358. rotation: '${rotation}'
  359. Spec:
  360. .. code-block:: yaml
  361. {
  362. ...
  363. chart1:{
  364. content: '<svg>SVG content</svg>'
  365. },
  366. ...
  367. }
  368. then, the content its rendered inside the print page with the layout configuration.
  369. Columns block
  370. -------------
  371. .. code-block:: yaml
  372. - !columns
  373. ? config: {TABLE_CONFIG}
  374. ? widths: [25,25,25,25]
  375. ? backgroundColor: #FFFFFF
  376. ? absoluteX: null
  377. ? absoluteY: null
  378. ? width: {PAGE_WIDTH}
  379. ? spacingAfter: 0
  380. ? nbColumns: -1
  381. items:
  382. - {BLOCK_DEFINITION}
  383. {...}
  384. Can be called **!table** as well.
  385. By default, the width of the columns will be equal.
  386. Each item will be in its own column.
  387. If the **absoluteX**, **absoluteY** and **width** are given, the columns block will be floating on top of the page at the specified position.
  388. The **widths** attribute can be used to change the width of the columns (by default, they have the same width). It must contain one integer for each column. The width of a given column is `tableWidth*columnWeight/sum(columnWeight)`.
  389. Every block type is allowed except for **map** if the column has an absolute position.
  390. Look at
  391. <http://trac.mapfish.org/trac/mapfish/wiki/PrintModuleServer#Tableconfiguration
  392. to know how to specify the **config** field.
  393. Map block
  394. ---------
  395. Allowed only within a **mainPage**.
  396. .. code-block:: yaml
  397. - !map
  398. width: 0
  399. height: 0
  400. ? name: map
  401. ? spacingAfter: 0
  402. ? align: left
  403. ? vertAlign: middle
  404. ? absoluteX: null
  405. ? absoluteY: null
  406. ? overviewMap: null
  407. ? backgroundColor: #FFFFFF
  408. **width** and **height** are mandatory. You can use variable substitution in this part, but if you do so, the browser won't receive the map size when it calls **info.json**. You'll have to **override mapfish.widgets.print.Base.configReceived** and set the map width and height of your layouts.
  409. If the **absoluteX** and **absoluteY** are given, the map block will be floating on top of the page at the specified position.
  410. The **name** is what will be displayed in the Acrobat's reader layer panel. The map layers will be displayed bellow it.
  411. If **overviewMap** is specified, the map will be an overview of the extent augmented by the given factor. There are few cases to consider with map overviews:
  412. 1. If there is no overview overrides and no OL.Control.MapOverview, then all the layers will figure in the PDF map overview.
  413. 2. If there are overview overrides, the OL map overview control is ignored.
  414. 3. If there are no overview overrides and there is an OL.Control.MapOverview (takes the first one), then the layers defined in the control are taken into account. By default it is the current base layer.
  415. Scalebar block
  416. --------------
  417. Display a scalebar.
  418. Allowed only within a **mainPage**.
  419. .. code-block:: yaml
  420. - !scalebar
  421. maxSize: 150
  422. ? type: line
  423. ? intervals: 3
  424. ? subIntervals: false
  425. ? units: m
  426. ? barSize: 5
  427. ? lineWidth: 1
  428. ? barDirection: up
  429. ? textDirection: up
  430. ? labelDistance: 3
  431. ? font: Helvetica
  432. ? fontSize: 12
  433. ? fontColor: black
  434. ? color: #000000
  435. ? barBgColor: null
  436. ? spacingAfter: 0
  437. ? align: left
  438. ? vertAlign: middle
  439. ? backgroundColor: #FFFFFF
  440. ? lockUnits: true
  441. ? preferredIntervals: [1,2,5,10]
  442. ? preferredIntervalFractions: 0.0
  443. The scalebar, will adapt its width up to `maxSize` (includes the labels) in order to have a multiple of 1, 2 or 5 values at each graduation. For example:
  444. * 0, 1, 2, ...
  445. * 0, 2, 4, ...
  446. * 0, 5, 10, ...
  447. * 0, 10, 20, ...
  448. The `barSize` is the thickness of the bar or the height of the tick marks on the line. The `lineWith` is for the thickness of the lines (or bar border).
  449. Units can be any of:
  450. * m (mm, cm, m or km)
  451. * ft (in, ft, yd, mi)
  452. * degrees (min, sec, °)
  453. If the value is too big or too small, the module will switch to one of the unit in parenthesis (the same unit is used for every intervals). If this behaviour is not desired, the lockUnits parameter will force the declared unit (or map unit if no unit is declared) to be used for the scalebar.
  454. The number of `intervals` can be set to anything >=2. Labels are drawn only at main intervals. If there is no space to display a label at a certain interval, this label won't be displayed. If `subIntervals` are enabled, their number will depend on the length of an interval.
  455. The type can be:
  456. * line: A simple line with graduations
  457. * bar: A thick bar with a suite of color and barBgColor blocks.
  458. * bar_sub: Like bar, but with little lines for labels.
  459. .. image:: images/scalebarTypes.png
  460. The bar and/or text orientation can be set to "up", "down", "left" or "right".
  461. The `align` attribute is for placing the whole scalebar withing the surrounding column or page. The `vertAlign` attribute is used only when placed in a column.
  462. Labels are always centered on the graduation, at a distance specified by labelDistance.
  463. Custom intervals in ScalebarBlock
  464. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  465. With this improvement we added two new configuration parameters to `!scalebar` blocks that allow to customize the scalebar preferred bar lengths.
  466. Now this set can be customized using the `preferredIntervals` property. This property is an array with the new (integer) allowed lengths. By default these were chosen in the `1`,`2`,`5`,`10` set.
  467. Another property, `preferredIntervalFractions`, can be specified to also use fractional intervals. By default only `0.0` is used, and thus only integer lengths are allowed.
  468. Example::
  469. .. code-block:: yaml
  470. preferredIntervals: [1,3,5,10]
  471. preferredIntervalFractions: [0.2,0.5]
  472. Attributes block
  473. ----------------
  474. Allows to display a table of the displayed feature's attributes.
  475. Allowed only within a *mainPage*.
  476. .. code-block:: yaml
  477. - !attributes
  478. source: results
  479. ? tableConfig: {TABLE_CONFIG}
  480. columnDefs:
  481. {COLUMN_NAME}:
  482. ? columnWeight: 0 MF_V1.2
  483. header: {BLOCK_DEFINITION}
  484. cell: {BLOCK_DEFINITION}
  485. {...}
  486. Look `here <configuration.html#table-configuration>`_ for how to specify the *tableConfig* field.
  487. The *columnWeigth* (MF_V1.2 only) allows to define a weight for the column width. If you specify it for one column, you have to specify it for all of them. The width of a given column is tableWidth*columnWeight/sum(columnWeight).
  488. The **source** value defines the name of the entry in the root of the client's **spec**. For example, it would look like that:
  489. .. code-block:: yaml
  490. {
  491. ...
  492. pages: [
  493. {
  494. ...
  495. results: {
  496. data: [
  497. {id:1, name: 'blah', icon: 'icon_pan'},
  498. ...
  499. ],
  500. columns: ['id', 'name', 'icon']
  501. }
  502. }
  503. ]
  504. ...
  505. }
  506. With this spec you would have to define 3 columnDefs with the names **id**, **name** and **icon**. Each cell definition blocks have access to all the values of the current row.
  507. The spec part is filled automatically by the 2 MapFish widgets when their `grids <http://www.mapfish.org/apidoc/trunk/files/mapfish/widgets/print/Base-js.html#mapfish.widgets.print.Base.grids>`_ parameter is set.
  508. Here is a crazy example of columnDef that will show the name of the icon and it's bitmap side-by-side inside a single column:
  509. .. code-block:: yaml
  510. columnDefs:
  511. icon:
  512. header: !text
  513. text: Symbol
  514. backgroundColor: #A0A0A0
  515. cell: !columns
  516. items:
  517. - !text
  518. text: '${icon}'
  519. - !image
  520. align: center
  521. maxWidth: 15
  522. maxHeight: 15
  523. url: 'http://www.mapfish.org/svn/mapfish/trunk/MapFish/client/mfbase/mapfish/img/${icon}.png'
  524. A more complex example can be found in SVN: `config.yaml <https://github.com/mapfish/mapfish-print-v2/tree/main/samples/config.yaml>`_ `spec.json <https://github.com/mapfish/mapfish-print-v2/tree/main/samples/spec.json>`_
  525. The print widgets are able to fill the spec for you based on a dictionary of **Ext.grid.GridPanel**. Just pass them through the grids parameter.
  526. Group Rendering In Attribute Blocks
  527. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  528. Attribute blocks now support grouping, by a specific attribute. Rows should be sorted by that attribute for grouping to work (no automatic sort is accomplished by the printing library).
  529. To identify the grouping attribute, use the `groupBy` property.
  530. Each group can be prefixed by a title, using the `groupTitle` property. You can specify any block in the `groupTitle` property, to render any kind of content as a title.
  531. You can also skip table header using the `includeHeader` flag (true by default).
  532. Finally you can force a page break before any new group, using the `groupOnNewPage` flag.
  533. Legends block
  534. -------------
  535. Display each layers along with its classes (icons and labels).
  536. .. code-block:: yaml
  537. - !legends
  538. ? backgroundColor: #FFFFFF
  539. ? borders: false
  540. ? horizontalAlignment: center
  541. ? maxWidth: 0
  542. ? maxHeight: 0
  543. ? iconMaxWidth: 0
  544. ? iconMaxHeight: 8
  545. ? iconPadding: 8 7 6 5
  546. ? textMaxWidth: 8
  547. ? textMaxHeight: 8
  548. ? textPadding: 8 7 6 5
  549. ? defaultScale: 1.0
  550. ? inline: true
  551. ? classIndentation: 20
  552. ? layerSpaceBefore: 5
  553. ? layerSpace: 5
  554. ? classSpace: 2
  555. ? layerFont: Helvetica
  556. ? layerFontSize: 10
  557. ? classFont: Helvetica
  558. ? classFontSize: 8
  559. ? fontEncoding: Cp1252
  560. ? columnMargin: 3
  561. ? overflow: false
  562. ? maxColumns: 1
  563. ? reorderColumns: false
  564. ? dontBreakItems: false
  565. ? fitWidth: 0
  566. ? fitHeight: 0
  567. **borders** is mainly for debugging purpouses and shows all borders in the legend tables. This can be either 'true' or 'false'.
  568. **horizontalAlignment** can be left, right or center (default) and aligns all items left, right or in the center.
  569. **iconMaxWidth**, **iconMaxHeight**, **defaultScale** with value of 0 indicate that the value will be ignored, i.e. the values are automatically set to the equivalent of Infinity, Infinity and 1 respectively. If the legends URL passed to MapFish (see http://mapfish.org/doc/print/protocol.html#print-pdf) are obtained from a WMS GetLegendGraphic request, the width/height are only indicative (even more when a label text is included with `LEGEND_OPTIONS/forceLabels parameter <https://docs.geoserver.org/stable/en/user/services/wms/get_legend_graphic/index.html#controlling-legend-appearance-with-legend-options>`_) and it would be safer, in order to preserve scale coherence between legends and map, to set **iconMaxWidth** and **iconMaxHeight** to zero.
  570. **textMaxWidth/Height** and **iconMaxWidth/Height** define how wide/high the text/icon cells of a legend item can be. At this point textMaxHeight is ignored.
  571. **textPadding** and **iconPadding** can be used like standard CSS padding. In the above example 8 is the padding top, 7 padding right, 6 padding bottom and 5 padding left.
  572. if **inline** is true icons and text are rendered on the same line, BUT multicolumn is still enabled.
  573. if **maxWidth** is set the whole legend gets a maximum width, just like other blocks. Note that **maxWidth** does not have any impact on icons size, thus icons may overflow outside the legends block.
  574. if **maxHeight** is set the whole legend gets a maximum height. This forces more than one column to appear if the legend is higher than the specified value. This can be used to enable the multi-column layout. 0 makes the maxHeight= max value, i.e. the equivalent of infinity.
  575. if **defaultScale** is non null it means that the legend image will be scaled so it doesn't take the full space. This can be overriden for individual classes in the spec JSON sent to the print module by adding an attribute called 'scale' and giving it a number. In conjunction with iconMaxWidth/Height this can be used to control average and also maximum width/height. If **defaultScale** equals 1, one pixel is scaled to one point (1/72 inch) in generated PDF. By default, as GeoServer legends are generated with ~90 dpi resolution (exactly 25.4/0.28), setting **defaultScale** value to 0.7937 (72*0.28/25.4) produces legend icons of same size as corresponding map icons. As the `LEGEND_OPTIONS/dpi GeoServer parameter <https://docs.geoserver.org/stable/en/user/services/wms/get_legend_graphic/index.html#controlling-legend-appearance-with-legend-options>`_ is not handled by MapFish, the resolution will necessary be ~91 dpi, which may cause visual quality difference with the map.
  576. For this to work, you need to set the **layerTree** config option on MF print widgets,
  577. more precisely the legends should be present in the print.pdf JSON request.
  578. **layerSpaceBefore** is to specify the space before the second and consecutive layers.
  579. **layerSpace** and **classSpace** is to specify the line space to add after layers and classes.
  580. **columnMaxWidth** maximum width of a column in multi-column layout.
  581. **maxColumns** allows to specify a maximum number of columns to be used. After this number is reached, a new row is created.
  582. **classIndentation** amount of points to indent classes by.
  583. **layerSpaceBefore** if a layer is after another one, this defines the amount of space to have before it. This will not be applied if the layer is the first item in its column in multi-column layout.
  584. **layerFont** font of layer name legend items.
  585. **layerFontSize** font size of layer name.
  586. **classFont** font of class legend items.
  587. **classFontSize** font size of class.
  588. **fontEncoding** (see below)
  589. Legend fitting
  590. ^^^^^^^^^^^^^^
  591. Support for legend fitting (legend resized to fit a given rectangle) has been added, through 2 new config.yaml configuration properties (to be used in legend blocks).
  592. The properties are:
  593. * `fitWidth`: width of the rectangle for fitting (defaults to 0, meaning no fit)
  594. * `fitHeight`: height of the rectangle for fitting (defaults to 0, meaning no fit)
  595. Both properties or only one of them can be specified. When only one property is set, the other dimension is calculated to mantain the original aspect ratio for the legend.
  596. Multipage legends
  597. ^^^^^^^^^^^^^^^^^
  598. By default a LegendsBlock must be contained in a single page. To allow it to span on several pages the `overflow` option can be used, setting it to true.
  599. When this option is used you also need to define `maxColumns`, to fix the max number of columns on each page and `maxHeight`, to fix the maximum height of each column.
  600. The LegendsBlock will be rendered on as many pages as needed to get all the items rendered with the given constraints.
  601. Please note that if more than one page is needed, the second and following pages will only contain legend columns, without any of the other element of the page where the legends block is defined.
  602. Creating an horizontal layout for legends
  603. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  604. Using some ``config.yaml`` configuration options in an unusual way it is possible to have a layout for legends that is horizontal, instead of vertical.
  605. To get this behaviour is necessary to:
  606. * use the legend block ``maxHeight`` property with a very low value (e.g. 1) to force a new column for each legend item
  607. * use the legend block ``maxColumns`` value to choose the number of columns for the legend (a new row will be forced after ``maxColumns`` is reached)
  608. Reorder legends block in columns
  609. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  610. When the option `reorderColumns` inside legends block it set to `true` and more than one column is necessary for the legends block, a new algorithm computes the best distribution of the legend items inside the columns. Currently a first fit with items sorted in height descending order is used. This is not sub-optimal, but it's fast.
  611. When a legend item is rendered to another column, by default name and legend icon could finish on different columns. To fix it, please enable the `dontBreakItems` option.
  612. Don't break legend items
  613. ^^^^^^^^^^^^^^^^^^^^^^^^
  614. Set the flag `dontBreakItems` to `true` on legends block if you want to render legend and names as one table to forbid the break between different columns
  615. Table configuration
  616. -------------------
  617. The `columns block <#columns-block>`_ and the `attributes block <#attributes-block>`_ can take a table configuration object like that:
  618. .. code-block:: yaml
  619. config:
  620. ? borderWidth: 0
  621. ? borderWidthLeft: 0
  622. ? borderWidthRight: 0
  623. ? borderWidthTop: 0
  624. ? borderWidthBottom: 0
  625. ? borderColor: black
  626. ? borderColorLeft: black
  627. ? borderColorRight: black
  628. ? borderColorTop: black
  629. ? borderColorBottom: black
  630. ? cells:
  631. ? - {CELL_CONFIGURATION}
  632. A cell configuration looks like that:
  633. .. code-block:: yaml
  634. ? row: {...}
  635. ? col: {...}
  636. ? borderWidth: 0
  637. ? borderWidthLeft: 0
  638. ? borderWidthRight: 0
  639. ? borderWidthTop: 0
  640. ? borderWidthBottom: 0
  641. ? borderColor: black
  642. ? borderColorLeft: black
  643. ? borderColorRight: black
  644. ? borderColorTop: black
  645. ? borderColorBottom: black
  646. ? padding: 0
  647. ? paddingLeft: 0
  648. ? paddingRight: 0
  649. ? paddingTop: 0
  650. ? paddingBottom: 0
  651. ? backgroundColor: white
  652. ? align: LEFT
  653. ? vertAlign: TOP
  654. The stuff configured at table level is for the table border, not every cell.
  655. The **cells** list defines overrides for some cells. The cells an override is applied to is defined by the **row** and **col** attribute. Those attributes can have several formats:
  656. * **0**: apply only to row or column 0 (the first)
  657. * **0-10**: applies only the row or columns from 0 to 10
  658. * or you can use any regular expression
  659. Every matching overrides is applied in order and will override the values defined in the previous ones.
  660. For example, if you want to draw an attribute block like that:
  661. .. image:: images/tableConfig.png
  662. You define that:
  663. .. code-block:: yaml
  664. - !attributes
  665. tableConfig:
  666. borderWidth: 1
  667. cells:
  668. # match every cell (default cell formatting)
  669. - borderWidthBottom: 0.5
  670. borderWidthLeft: 0.5
  671. padding: 4
  672. paddingTop: 0
  673. # match every even cell (yellowish background)
  674. - row: '\d*[02468]'
  675. backgroundColor: #FFFFCC
  676. # for the header
  677. - row: 0
  678. borderWidthBottom: 1
  679. backgroundColor: #FA0002
  680. align: center
  681. {...}
  682. Dynamic images page
  683. -------------------
  684. New layout to let you print a different number of pages dinamically.
  685. You need to put it in :file:`config.yaml`:
  686. .. code-block:: yaml
  687. dynamicImagesPage:
  688. rotation: true
  689. pageSize: 595 842
  690. landscape: false
  691. items:[...]
  692. and when you called to the print servlet, you'll need to add this property to the spec:
  693. .. code-block:: yaml
  694. imagesPages:[
  695. {firstPageConfiguration},
  696. {secondPageConfiguration}
  697. ]
  698. then it's render one page for each item found in the imagesPages property.
  699. Also, you cant select the pages placement inside the document with the property `renderOn`:
  700. * `afterLastPage`: It's rendered after the last page. It's the default option active.
  701. * `beforeLastPage`: It's rendered just before last page (between main page and last page layouts)
  702. * `beforeMainPage`: It's rendered before main page (between first page and main page)
  703. The first use of this layout it's add a dynamic number of pages with differents images with svg content generated dynamicaly (using also the images content enhancement). This is an example of use with two dynammic images by page:
  704. Example :file:`config.yaml`:
  705. .. code-block:: yaml
  706. ...
  707. dynamicImagesPage:
  708. rotation: true
  709. pageSize: 595 842
  710. landscape: false
  711. items:
  712. - !columns
  713. absoluteX: 30
  714. absoluteY: 812
  715. width: 535
  716. height: 100
  717. items:
  718. - !image
  719. maxWidth: 535
  720. url: '${configDir}/print_header.png'
  721. - !columns
  722. absoluteX: 0
  723. absoluteY: 750
  724. width: 595
  725. widths: [595]
  726. items:
  727. - !text
  728. align: center
  729. vertAlign: middle
  730. fontSize: 14
  731. text: '${meteorologicalPagesTitle}'
  732. - !columns
  733. width: 580
  734. height: 271
  735. absoluteX:70
  736. absoluteY:697
  737. items:
  738. - !image
  739. name: chart1
  740. maxWidth: 580
  741. maxHeight: 271
  742. rotation: '${rotation}'
  743. - !columns
  744. width: 580
  745. height: 271
  746. absoluteX:70
  747. absoluteY:400
  748. items:
  749. - !image
  750. name: chart2
  751. maxWidth: 580
  752. maxHeight: 271
  753. rotation: '${rotation}'
  754. spec:
  755. .. code-block:: yaml
  756. {
  757. ...
  758. imagePages:[
  759. images:{
  760. chart1:{
  761. content: '<svg>SVG content</svg>'
  762. },
  763. chart2:{
  764. content: '<svg>SVG content</svg>'
  765. }
  766. }
  767. ],
  768. ...
  769. }