8

I want to create a PDF from WMS in a web map application.

Please can anyone recommend a robust component? I'd like free open-source under an relatively business-friendly licence (no GPL, BSD/MIT etc. would be ideal, LGPL would be OK).

  • Our WMS layers are produced by ncWMS and UNM MapServer. We will also want to overlay some layers from external WMS providers.
  • EDIT: We are developing our own JavaScript client based on OpenLayers.
  • EDIT: We have some backend code in Java. We would also consider PHP or other platforms to create the PDF.

MapFish would be excellent but it is GPL.

MarkJ
  • 396
  • 1
  • 12
  • 1
    QGIS Server and Client offer high-resolution PDF output parallel to WMS but it's GPL too. – underdark Sep 22 '11 at 08:46
  • What server software is providing the WMS service? – Allan Adair Sep 22 '11 at 08:56
  • @Allan I have answered in an edit – MarkJ Sep 22 '11 at 09:51
  • 2
    I think MapServer supports PDF output (http://mapserver.org/output/pdf.html), and the newer version uses Cairo (http://cairographics.org/), which is released under LGPL or MPL. – Allan Adair Sep 22 '11 at 10:04
  • @Allan Good point. You could make that comment an answer! Question: would we have to create a MAP file? Currently we don't have a map file which contains all the layers, we are assembling them in the client using OpenLayers. I suppose our JavaScript front end would call back to the server, which would then execute some MapScript. Would we also have to make a MAP file? – MarkJ Sep 22 '11 at 13:34
  • The MapFish print module can be set up as a standalone Java application, so unless you are bundling up your app to sell I'm not sure of the problem with GPL. – geographika Sep 22 '11 at 14:04
  • Markj: I also think mapserver is the best option. For the external wms clients you have to add maplayers, but the rest of your mapfile can stay identical. Setting the scale/extent can be done through mapscript. – johanvdw Sep 22 '11 at 14:26
  • @geographika I will be bundling up my app to sell – MarkJ Sep 23 '11 at 07:52
  • @Allan and others. Sounds like creating the MAP file could be a bit fiddly (might need to pass time and elevation to some of the external WMS servers). I think I'm more inclined to use a low-level PDF library and create our own WMS requests to get the image. Thanks for the suggestions though! – MarkJ Sep 30 '11 at 08:31
  • @MarkJ, cool, let us know what you end up using. – Allan Adair Sep 30 '11 at 13:07
  • @AllanAdair I have posted a CW answer explaining what we did – MarkJ Nov 30 '11 at 11:30
  • @MarkJ I have been browsing the answers and comments but haven't found anything specific about what the actual client application is in developed in. I followed your link to ncWMS; are you using the Godiva2 web client? I was involved in building an application that used Adobe Flex on the client side, and we used AlivePDF. – Baskinomics Dec 08 '11 at 02:06
  • @sbaskin89 We are developing our own JavaScript client rather than using ncWMS. I should have really have specified that in the question in the first place, I will edit it in. AlivePDF looks interesting for Flex users though. Thanks very much for the input! – MarkJ Dec 08 '11 at 12:31
  • Just noticed that this question about Python libs for combing WMS and WFS into PDF is related to my question. – MarkJ Nov 15 '12 at 18:05

4 Answers4

3

I use Cairo and Pango (both LGPL) together to create PDF maps.

It's a low level solution, but Cairo has superb vector drawing and raster handling capabilities, whilst Pango is excellent at typesetting. The overall results are great, but it does require a lot of coding. For instance if I want to create a map using a WMS output I construct a WMS request, request the image and draw it onto a PDF canvas using Cairo.

I use these libraries via Java-Gnome but there are bindings to both in most languages.

MarkJ
  • 396
  • 1
  • 12
Will
  • 176
  • 3
  • If you consider this option, you could also look to libharu (in C) or older versions of iText (java)(newer have a AGPL license which will not fit your purpose). – johanvdw Sep 22 '11 at 14:23
  • 1
    For examples of maps created almost entirely using this method please see this publication. Additional file 2 contains the maps, which were originally vector but have been rasterized to reduce download size. – Will Sep 22 '11 at 15:24
  • @johanvdw Indeed the AGPL does not fit my purpose. I might consider PDFBox which is under the Apache licence – MarkJ Sep 23 '11 at 07:56
  • @Will Cairo sounds interesting. Our production server is Linux but our development/test machines are Windows. Is there any way to use Cairo from Java on Windows? – MarkJ Oct 10 '11 at 14:47
  • @MarkJ java-gnome doesn't run on Windows unfortunately (and it's GPL) - I haven't found an alternative. The Python and Mono bindings run on Windows though. – Will Oct 10 '11 at 15:34
3

What about using http://code.google.com/p/wkhtmltopdf/ ? It is lgpl and allows you to simply generate a pdf from a web page template. We use this approach together with django to dynamically generate the html before rendering it to pdf with wkhtml.

Regards

Tim

Tim Sutton
  • 337
  • 1
  • 1
  • +1. Although tricky with OpenLayers vectors, this solution allows you to fully customize printout page. Put logos, legends, footers wherever you want just like on usual html page, then create image or pdf from it. – denu Dec 08 '11 at 14:21
  • +1 for lateral thinking alone! To be sure I've understood: you would create a webpage displaying some map layers using a JavaScript client (e.g. OpenLayers), and then render it to PDF with wkhtml? – MarkJ Dec 08 '11 at 15:27
  • Hi Tim, how did you get this to work? I tried some examples with Open Layers, but the map doesnt get rendered, or it is compressed to the left side of the box. – Dennis van Schaik Jun 20 '16 at 07:23
0

Well, we used PDFBox (Apache licence) from Java server-side code.

We construct WMS requests for the various layers, get images as in-memory bitmaps, and overlay them into one single in-memory bitmap. Using Java BufferedImage for the in-memory bitmaps. Then we render the bitmap onto the PDF page using PDFBox PDJpeg.

It works pretty well. One niggle is that the map images can become slightly blurry in the PDF, since you have to encode them as JPEG in order to use them with PDFBox, with the inevitable lossy compression. You can ameliorate this by setting the JPEG quality to the maximum in the PDFJpeg constructor, and by requesting the images at a large size (e.g. 300 dpi).

Eventually we plan to release our code as open-source. I will post a link when this happens.

Thanks again to Will, Allan and everyone!

MarkJ
  • 396
  • 1
  • 12
0

Geomajas has a printing plug-in which can convert your map to PDF and also a reporting plug-in (in progress) which can be used to build a report using JasperReports which can include the map image. Both are AGPL but a business friendly license can be requested (provided by Geosparc).

  • Thanks, I had not heard of Geomajas, that's interesting. Although I notice they charge for the business-friendly licences and the printing module uses iText which again means you must pay to be released from the AGPL – MarkJ Dec 08 '11 at 12:40