Printing 2.0 HOWTO

Look at this beautiful PDF you can make!

Mapfish has a pretty nice printing library that generates nice PDF files. Its documentation is available to interested parties (probably you) for perusal. I am working on integrating its capabilities as a module for Geoserver.  So far, I've gotten the library to the point where its basic functionality is available; I will go on refining it from here on out.

As-is, you can use it to add buttons/forms to OpenLayers maps that allow you to print things out, as in this example.

The Mapfish printing module is licensed and distributed under the GPLv3 license.

Installation on GeoServer 2.0.x release

  1. Download the printing extension and extract the zip to the library folder of your GeoServer webapp. In a binary install this is [GEOSERVER_HOME]/webapps/geoserver/WEB-INF/lib/.
  2. Download the sample configuration and application and extract the zip to the root of your [GEOSERVER_DATA_DIR].
  3. The example printing application will be available at http://localhost:8080/geoserver/www/Printing/examples/Printing.html. This example is based on GeoExt.ux, which requires you to accept the Ext JS license terms.
  4. If you would like to modify the MapFish configuration, its documentation is available.  This allows you to grab data from other sources than localhost and change the appearance of printed documents.

Installation on 2.0.x trunk

There are two ways to try out the printing module--- either build the server yourself or install some JARs into a nightly build.

Method 1: Building GeoServer with the printing module:

  1. Check out or update the trunk.
  2. Navigate to the src/ directory in your copy of the trunk.
  3. Run this command:
    mvn clean install -Pweb2 -Pprinting
  4. Install the configuration & example application as documented below.
  5. Start the server by navigating to the src/community/web2/app subdirectory of the GeoServer trunk and then running this command:
    mvn jetty:run -DGEOSERVER_DATA_DIR=[PATH_TO_YOUR_GS_DATA_DIR] -Pprinting
  6. The example printing application will be available at http://localhost:8080/geoserver/www/mf/examples/print/simple.html.

Method 2: Adding the printing module to a nightly build

  1. Grab a copy of the nightly build of GeoServer's trunk.  Install it per instructions.
  2. Grab print-nightly.zip, which has the necessary library files to add the printing functionality to GeoServer.
  3. Extract the zip you just downloaded to the root directory of the nightly you just installed, or manually extract all the JARs to $GEOSERVER_HOME/webapps/geoserver/WEB-INF/lib.
  4. Install the configuration & example application as documented below.
  5. Start GeoServer as described in $GEOSERVER_HOME/RUNNING.txt, or by running bin/startup.sh from $GEOSERVER_HOME.
  6. The example printing application will be available at http://localhost:8080/geoserver/www/mf/examples/print/simple.html.

Installing the default configuration and an example application:

  1. Grab the sample configuration & interface, attached to this document as printing-data.zip.  Extract it to the root of your GeoServer data directory, $GEOSERVER_DATA_DIR.
  2. If you would like to modify the MapFish configuration, its documentationis available.  This allows you to grab data from other sources than localhost and change the appearance of printed documents.

Configuration

Adding your own layers

  1. Open up www/mf/examples/print/simple.html in your data directory.
  2. In the Javascript, there appear several lines like these:
    var usa = new OpenLayers.Layer.WMS("MURRICA",
    "http://localhost:8080/geoserver/wms?",
    {layers: ['topp:states'], format: 'image/png', transparent: true},
    {visibility: true, singleTile: true})
    map.addLayer(usa);
    

    Just copy and paste one of those sets of lines, and edit the variable name, layer title, and layer name as appropriate.

  3. OpenLayers provides more elaborate documentation at their own site.

Troubleshooting

Send me an email--- my address is on my profile page.
Or visit #geoserver on irc.freenode.net--- I'm there as agerber.

Added by Alan Gerber, last edited by Andreas Hocevar on May 28, 2010  (view change)
View Attachments (7) Info