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
MapFish lets you access three different points:
info.jsonthat returns current config as defined in config.yaml file
print.pdfthat actually prints the map as defined in the
create.jsonthat 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
create.json, otherwise you’ll be getting an error complaining about the GET request length.
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.
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).