Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
1  
QGIS Server and Client offer high-resolution PDF output parallel to WMS but it's GPL too. –  underdark Sep 22 '11 at 8:46
    
What server software is providing the WMS service? –  Allan Adair Sep 22 '11 at 8:56
    
@Allan I have answered in an edit –  MarkJ Sep 22 '11 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. –  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

4 Answers 4

up vote 3 down vote accepted

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.

share|improve this answer
    
+1. Thanks! You are a candidate for the accepted answer, I'm just waiting to see whether someone comes up with something better. Also took the liberty of editing in some hyperlinks. –  MarkJ Sep 22 '11 at 13:28
    
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 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 Oct 10 '11 at 14:47

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

share|improve this answer
    
+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 8 '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 8 '11 at 15:27

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).

share|improve this answer
    
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 8 '11 at 12:40

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!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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