Print legend with Geoserver Printing Module

i have defined the legend in the config.yaml like this:

lastPage:
      pageSize: A4
      items: 
      - !columns
          config: 
            borderWidth: 0.5
            borderColor: black
            cells:
                - padding: 5
          items:          
            - !legends 
              backgroundColor: #ff0000        
              spacingAfter: 20 

the legends are delivered right, by json.
but the last page has just the black border and no legends is displayed…
someone any idea, what can be wrong? in the log file is nothing visible

I help make releases of the mapfish-print-v2 library used for PDF generation - but I do not especially understand how it works. I think it is making GetMap requests as it operates?

With that in mind perhaps check the GeoServer logs to see if requests an empty map?

Thanks a lot for your answer.
The printing of the map works fine. Just the legend is not printed. This is the json for the legends, which is sent with the print request:

legends: {
    "name": "",
    "classes": [
        {
            "name": "Amtliche Vermessung",
            "icons": [
                "[URL to the PNG]"
            ],
            "iconBeforeName": true
        }
    ]
}

and this is what i have defined in the config.yaml:

lastPage:
      pageSize: A4
      items: 
      - !columns
          config: 
            borderWidth: 0.5
            borderColor: black
            cells:
                - padding: 5
          items:          
            - !legends 
              backgroundColor: #ff0000        
              spacingAfter: 20 

but the last page is just empty

ok i found the issue. the problem was, that legends was not an array in my json.

but there is another challenge now. because i got just one image with the whole legend on it, it is too small, because the whole legend is displayed like one small icon. is there a solution to scale this image?

solved it, too with this config:

- !legends 
              align: left
              maxWidth: 515
              maxHeight: 686   
              iconMaxWidth: 515
              iconMaxHeight: 686         
              textMaxWidth: 100   
              fitWidth: 515
              fitHeight: 686 
              defaultScale: 1.0
              backgroundColor: #ff0000    
              spacingAfter: 20 
              inline: false
              layerSpaceBefore: 0
              layerSpace: 0
              classSpace: 0

lol - that is great! and thanks so much for sharing the answer.

If you have any suggestions, or are comfortable making examples for the docs they would be much appreciated. GeoSever has how to add to docs, and the same approach works for the configuration page.

aside: I edited your posts to be markdown so I could understand your yaml examples.

1 Like