0

I have a vector layer in Geoserver 2.15.1 and displaying it on map div using Openlayers v5 API. When displaying the vector data on map, I am using custom style body and passing it to the layer's style parameter.

Now when taking a print using Mapfish extension installed on Geoserver, the empty PDF has been generated with an exception as "com.itextpdf.text.exceptions.InvalidPdfException: PDF header signature not found.".

I feel the problem is the style parameter used in print URL.

http://milky.com:8080/geoserver/pdf/print.pdf?spec={"layout":"A3 portrait","srs":"EPSG:3857","units":"m","dpi":300,"outputFilename": "gh","layers":[{"baseURL":"http://milky.com:8080/geoserver/cite/wms","opacity":1,"singleTile":true,"customParams":{},"type":"WMS","version":"1.3.0","layers":["VIC_Graphical"],"format":"application/pdf","styles":["<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><StyledLayerDescriptor version=\"1.0.0\" xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" xmlns=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><NamedLayer><Name>cite:VIC_Graphical</Name><UserStyle><Title>DCDB Graphical Status</Title><Abstract>A sample style that draws a Hollow polygon</Abstract><FeatureTypeStyle><Rule><Name>Yet To Start</Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>status_code</ogc:PropertyName><ogc:Literal>0</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><PolygonSymbolizer><Fill><CssParameter name=\"fill\">%23EBBC8E</CssParameter></Fill><Stroke><CssParameter name=\"stroke\">%23dd8c3c</CssParameter></Stroke></PolygonSymbolizer></Rule><Rule><Name>Data Capture Completed</Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>status_code</ogc:PropertyName><ogc:Literal>1</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><PolygonSymbolizer><Fill><CssParameter name=\"fill\">%2366B2FF</CssParameter></Fill><Stroke><CssParameter name=\"stroke\">%230073e6</CssParameter></Stroke></PolygonSymbolizer></Rule><Rule><Name>Quality Control Completed</Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>status_code</ogc:PropertyName><ogc:Literal>2</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><PolygonSymbolizer><Fill><CssParameter name=\"fill\">%2387BD72</CssParameter></Fill><Stroke><CssParameter name=\"stroke\">%23568b41</CssParameter></Stroke></PolygonSymbolizer></Rule><Rule><Name>Delivered</Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>status_code</ogc:PropertyName><ogc:Literal>3</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><PolygonSymbolizer><Fill><CssParameter name=\"fill\">%23FF99FF</CssParameter> </Fill><Stroke><CssParameter name=\"stroke\">%23e600e6</CssParameter></Stroke></PolygonSymbolizer></Rule><Rule><Name>No Back Capture</Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>status_code</ogc:PropertyName><ogc:Literal>4</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><PolygonSymbolizer><Fill><CssParameter name=\"fill\">%23cccccc</CssParameter></Fill><Stroke><CssParameter name=\"stroke\">%23666666</CssParameter><CssParameter name=\"stroke-width\">0.01</CssParameter></Stroke></PolygonSymbolizer></Rule></FeatureTypeStyle> <FeatureTypeStyle><Rule><Name>LGA Boundary</Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>status_code</ogc:PropertyName><ogc:Literal>-1</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter> <PolygonSymbolizer><Stroke><CssParameter name=\"stroke\">%23858585</CssParameter><CssParameter name=\"stroke-dasharray\">3 2</CssParameter></Stroke></PolygonSymbolizer></Rule></FeatureTypeStyle> </UserStyle></NamedLayer></StyledLayerDescriptor>"]}],"pages":[{"center":[16230899.368029967,-4618261.021190349],"mapTitle":"jg","comment":"","company":"Default_A3_portrait","scale":2183915,"rotation":0}]}

And the sld body used passed in the print URL is,

<?xml version="1.0" encoding="ISO-8859-1"?><StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><NamedLayer><Name>cite:VIC_Graphical</Name><UserStyle><Title>DCDB Graphical Status</Title><Abstract>A sample style that draws a Hollow polygon</Abstract><FeatureTypeStyle><Rule><Name>Yet To Start</Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>status_code</ogc:PropertyName><ogc:Literal>0</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><PolygonSymbolizer><Fill><CssParameter name="fill">#EBBC8E</CssParameter></Fill><Stroke><CssParameter name="stroke">#dd8c3c</CssParameter></Stroke></PolygonSymbolizer></Rule><Rule><Name>Data Capture Completed</Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>status_code</ogc:PropertyName><ogc:Literal>1</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>  <PolygonSymbolizer><Fill><CssParameter name="fill">#66B2FF</CssParameter></Fill><Stroke><CssParameter name="stroke">#0073e6</CssParameter></Stroke></PolygonSymbolizer></Rule><Rule>   <Name>Quality Control Completed</Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>status_code</ogc:PropertyName><ogc:Literal>2</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter> <PolygonSymbolizer><Fill><CssParameter name="fill">#87BD72</CssParameter> </Fill><Stroke><CssParameter name="stroke">#568b41</CssParameter></Stroke></PolygonSymbolizer></Rule><Rule><Name>Delivered</Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>status_code</ogc:PropertyName><ogc:Literal>3</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><PolygonSymbolizer><Fill><CssParameter name="fill">#FF99FF</CssParameter></Fill><Stroke><CssParameter name="stroke">#e600e6</CssParameter></Stroke></PolygonSymbolizer></Rule><Rule><Name>No Back Capture</Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>status_code</ogc:PropertyName><ogc:Literal>4</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><PolygonSymbolizer><Fill><CssParameter name="fill">#cccccc</CssParameter></Fill><Stroke><CssParameter name="stroke">#666666</CssParameter><CssParameter name="stroke-width">0.01</CssParameter></Stroke></PolygonSymbolizer></Rule></FeatureTypeStyle> <FeatureTypeStyle><Rule><Name>LGA Boundary</Name>         <ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>status_code</ogc:PropertyName><ogc:Literal>-1</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>  <PolygonSymbolizer><Stroke><CssParameter name="stroke">#858585</CssParameter><CssParameter name="stroke-dasharray">3 2</CssParameter></Stroke></PolygonSymbolizer></Rule></FeatureTypeStyle> </UserStyle></NamedLayer></StyledLayerDescriptor>

I am very sure that there is no issue in the sld body as becacuse the same has been used to display the vector data on map.

As the values (color codes etc) for this sld body will be set dynamically from script, I can't create this as a static style file in Geoserver.

Seeking your advise on printing vector data with dynamic styles.

  • please add some more of the log file showing the error message. All that message says is that something went wrong making the PDF. One possibility is that you need to encode the SLD in the URL – Ian Turton Nov 8 '19 at 10:59
  • Yes I encoded # as %23 and " as \". I tried even encoding space and question marks as well but no success. Sure I will get the log from Geoserver and add in this – venkat Nov 8 '19 at 11:03
  • I resolved the PDF error now. Actually I made mistake that I passed sld in "styles" parameter instead of "sld_body" parameter. Now it is printed in the PDF. But now the issue is, it is printed with default style and not with the style passed through the sld_body text – venkat Nov 8 '19 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.