If you are using QGIS Server 2.18 please read this post QGIS Server 2.18 LTR Printing problem
If you are using Linux you can upgrade to QGIS Server 3.4 and don't have to deal with above fix for printing (also upgrade gisapp to 1.8.2 or higher)
To setup printing map to PDF in Web client with user data follow this:
- Set field
- Create print composer(s) in QGIS project (to enable print button)
- Make PostgreSQL connection to gisapp database in QGIS and add
users_print_viewto Layers panel. It will not show in Web client, just needs to be in layers panel.
- Add attribute table to print composer(s) and adjust it to show table
users_print_view. Because of the filter parameter upon printing this table will always hold only one record. Adjust attributes to show labels you want from user printing the map.
Available fields are:
FROM DATABASE FOR USER PRINTING THE MAP:
USER OWN DESCRIPTION AND TITLE ENTERED IN WEB CLIENT:
You can customize this and add table many times, for example on top for displaying title and larger font and somewhere else displaying description and user info with smaller font.
Note: This works only for registered users, guest users do not get option to write own title or description!
Web client contains map layer (=QGIS project) and optional base or overlay layers. GetPrint request is only send to QGIS server, so server must know base layer, if user wants to print it together with the map. Web client works much faster if calls are spread between QGIS project and other base layers (WMS, WMTS, OSM, Google,...).
Note: Use http protocol if possible. With QGIS 3 there are known issues with layers using https protocol.
So to achieve best performance and print currently selected base layer follow this:
- Add base layer as other layers into QGIS project and open Web client to see if the layer is in legend and available to use. Not all types are working, it is related to GDAL build with QGIS. For example on Ubuntu 2.14 with GDAL 1.11.3 it is possible to use WMS layers and OpenStreetMap (via QGIS OpenLayers plugin). With GDAL 2 also WMTS layers are working.
- If base layer is visible in Web Client, you can add it to database - Wiki documentation.
- Add its layer_id to table of projects as external base layer.
- Make sure that base layer in database (field
display_name) has same name also inside QGIS project. If this is the case then layer from QGIS project is hidden from legend tree in Web client and it will be only used for possible printing.
- When user prints a map with base layer visible and if same layer name exist in QGIS project then this layer is added to layers list and it will be added to the PDF.