Skip to content

Instantly share code, notes, and snippets.

@maptastik
Created January 12, 2017 18:19
Show Gist options
  • Save maptastik/a0c502e738cf9126175f6f490cfb9f15 to your computer and use it in GitHub Desktop.
Save maptastik/a0c502e738cf9126175f6f490cfb9f15 to your computer and use it in GitHub Desktop.
Export Data Driven Pages from ArcGIS in bulk as JPG and/or PDF

ddp_export.py

The purpose of this script is to bulk export data driven pages from ArcGIS. It generates output as JPG and/or PDF based on user input. This by inspired by an answer [the question about exporting data driven pages on GIS Stack Exchage] (http://gis.stackexchange.com/a/67520/27257).

To run this script:

  1. Open up cmd.exe (Command Prompt)
  2. Copy the location of where this script is located
  3. In the command prompt navigate to the directory containing this script: cd <path to directory>
  4. In the command prompt run the script: python ddp_export.py
  5. Follow the instructions.
# The purpose of this script is to bulk export data driven pages from ArcGIS.
# Output be JPG and/or PDF
# Inspired by http://gis.stackexchange.com/a/67520/27257
# TO RUN THIS SCRIPT:
# 1. Open up cmd.exe (Command Prompt)
# 2. Copy the location of where this script is located
# 3. In the command prompt navigate to the directory containing this script: cd <path to directory>
# 4. In the command prompt run the script: python ddp_export.py
# 5. Follow the instructions.
import arcpy
import os
# SPECIFY MXD TO EXPORT
mxd_dir = raw_input("Location of MXD: ") # Directory containing MXD
mxd_file = raw_input("Name of your MXD (Don\'t include .mxd extension): ") + ".mxd" # Name of MXD to be exported
mxd_path = mxd_dir + "\\" + mxd_file
mxd = arcpy.mapping.MapDocument(mxd_path)
# SPECIFY DATA DRIVEN SORT FIELD
ddp_sort_field = raw_input("Data Driven Pages sort field: ") # Name of field used to sort DDP
# SPECIFY EXPORT PROPERTIES
export_path = raw_input("Where you would like to export your output: ") # Path of output file
prefix = raw_input("File name prefix: ") # Add some prefix if you want.
formats = int(raw_input("1 = JPG & PDF | 2 = JPG | 3 = PDF: "))
# EXPORT TO JPG AND/OR PDF
for i in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = i
row = mxd.dataDrivenPages.pageRow
print row.getValue(ddp_sort_field)
if formats != 3:
arcpy.mapping.ExportToJPEG(mxd, export_path + "\\" + prefix + row.getValue(ddp_sort_field) + ".jpg")
if formats != 2:
arcpy.mapping.ExportToPDF(mxd, export_path + "\\" + prefix + row.getValue(ddp_sort_field) + ".pdf")
# CLEAN UP
del mxd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment