Geoserver Printing With Mapfish
Printing a web map requires a lot more than doing Ctrl + P
. MapFish seems to be the best option to use with Geoserver, and it comes ready as an extension. If you installed the module properly, you should be seeing general info at http://localhost:8080/geoserver/pdf/info.json. You’ll find a config.yaml
in data_dir/printing
.
MapFish lets you access three different points:
info.json
that returns current config as defined in config.yaml fileprint.pdf
that actually prints the map as defined in thespec
GET argumentcreate.json
that returns a JSON object with an URL of the printed map
Remember, if you’re displaying a lot of layers in the map and all of them should be printed, you need to pass it as a POST argument when calling print.pdf
or create.json
, otherwise you’ll be getting an error complaining about the GET request length.
The config.yaml
file is where you define settings for the print module. You definitely want to define dpis
(we’re using 90, 200 and 300 DPI), scales
(they probably need to be hardcoded, I didn’t succeed trying any arbitrary scale) and layouts
(we’re using A4 to A0 both portrait and landscape).
However, defining the page size might get tricky as MapFish does not use standardized sizes defined in cm, in or any other unit. I’ve experimenting and doing some maths and here’s what I came up with for portrait layouts.
A0 | A1 | A2 | A3 | A4 |
---|---|---|---|---|
2382×3361 | 1683×2380 | 1190×1680 | 840×1180 | 595×832 |
The bigger paper you use, the smaller DPI is available, that’s what I found out messing around with MapFish settings. This means that we’re using 200 DPI top for A2 layout and 90 DPI for A1 and A0 layout, respectively.
JQuery takes care of sending POST request and fetching the response. See it in action (Choose Nástroje and Tisknout for printing).