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.

14
  • 1
    QGIS Server and Client offer high-resolution PDF output parallel to WMS but it's GPL too.
    – underdark
    Commented Sep 22, 2011 at 8:46
  • What server software is providing the WMS service? Commented Sep 22, 2011 at 8:56
  • @Allan I have answered in an edit
    – MarkJ
    Commented Sep 22, 2011 at 9:51
  • 2
    I think MapServer supports PDF output (mapserver.org/output/pdf.html), and the newer version uses Cairo (cairographics.org), which is released under LGPL or MPL. Commented Sep 22, 2011 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
    Commented Sep 22, 2011 at 13:34

4 Answers 4

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.

5
  • 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
    Commented Sep 22, 2011 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
    Commented Sep 22, 2011 at 15:24
  • @johanvdw Indeed the AGPL does not fit my purpose. I might consider PDFBox which is under the Apache licence
    – MarkJ
    Commented Sep 23, 2011 at 7: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
    Commented Oct 10, 2011 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
    Commented Oct 10, 2011 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

3
  • +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
    Commented Dec 8, 2011 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
    Commented Dec 8, 2011 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. Commented Jun 20, 2016 at 7:23
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).

1
  • 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
    Commented Dec 8, 2011 at 12:40
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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.