Using ArcPy for multi-page exports

Apr 19, 2012   //   by Simon J   //   Other  //  1 Comment
Not UsefulUseful (+2 rating, 2 votes)
Loading ... Loading ...

It is great to see that the generic ArcPy sample we provided is getting a lot of download hits.

On a previous post, I did a video on how you can setup your Layout MXD to sync multiple data frames to the main data frame, so that you can display a variety of basemaps in separate data frames, all in the one printout.

I also did a post on how you can append a separate page into your one Dekho export, dedicated for a static legend.

But what happens if you wanted to click Print from Dekho once, but have a multi-page PDF, showing your area of interest with multiple basemaps on separate pages?

Our friends over at Eagle have been tweaking the ArcPy sample to do just this, for Dunedin City Council.

They are also taking advantage of fetching the data locally (avoiding any loss in quality by cutting out going via a map service) which improves print speed and output quality.

They have kindly shared the modified arcpy script, and this can be seen here (bulk of the tweaking is around lines 166 -208).

Setup:

  • The script utilises pyPDF to merge the individual PDFs into one PDF.
    You will need to download the zipped source code from this link.  This then needs to be deployed under your python folder e.g. C:\Python26\ArcGIS10.0\Lib
  • Either modify the existing DekhoServerPrint.py or create a new one, and publish to ArcGIS Server.
  • Create a layout MXD with multiple Data Frames.
  • (Optional) For the HQ Printing, you will need to ensure you add all the layers direct from the GDB, direct to the Layout MXD, and ensure they are turned off.
  • For multiple data frames the Python script will do the following for each data frame;
  1. Switch on all of the layers in the “current” data frame.
  2. Change the scale to what the user wants.
  3. Update the map name text to be the same as the data frame name.
  4. Export the layout to PDF
  5. Switch off all of the layers in the “current” data frame

Once all of the layouts have been exported they are stitched together using the pyPDF library and the final PDF is returned to Dekho.

The map name text comes from the data frame name.

As always, excellent work Eagle!  Would love to see how others are using ArcPy with Dekho…

1 Comment

  • I sit next to a python wizard (Thomas M) who thinks that you could possibly streamline this script further to reduce the need for the pyPDF library.

    Essentially you’d create a PDFDocument class based on the output (or perhaps a static template PDF) and then call the .appendPages or .insertPages methods to stick them together (see http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/PDFDocument/00s30000002w000000/).

    I have not had a chance to investigate this further, but if anyone is thinking about giving this a go, perhaps take a look at this approach. The fewer external dependencies the better.

Leave a comment


+ six = 13