FedGIS 2017 Resources: Desktop Mapping - Building Map Books

Blog Post created by BWhite-esristaff Employee on Feb 6, 2017

After attending the Desktop Mapping - Building Map Books session at FedGIS, are you ready to start creating map books of your own?


Here are some links to get you started:


Karreem shared the following map service during the presentation: NOS_Observations/CO_OPS_Products (FeatureServer).


Here's the code that Karreem shared:


import arcpy
import os
import string
import glob
import time
# Get the current working directory for the script
# Makes code portable
cwd = os.getcwd()

field_num = "Id"
field_desc = "Region"

print("Getting DDP....")

#Delete all pdf documents located in Exports
pdfList = glob.glob(cwd+"/../Exports/*.pdf")
for docs in pdfList:

#Create the new pdf book from scratch

data_name = "Sea Level Trends"

#Create final output PDF file
finalpdf_filename =cwd+"/../Exports/"+data_name+".pdf"
finalPdf = arcpy.mapping.PDFDocumentCreate(finalpdf_filename)

#PNG or JPEG only

    mxd = arcpy.mapping.MapDocument(cwd+"/../"+data_name+".mxd")
    #Create all pdf documents using DDP
    for i in range(1, mxd.dataDrivenPages.pageCount + 1):
       mxd.dataDrivenPages.currentPageID = i
       row = mxd.dataDrivenPages.pageRow
       print str(row.getValue(field_desc))
       #Print each Data Driven Page to an Individual PDF
       arcpy.mapping.ExportToPDF(mxd, cwd+"/../Exports/"+\
                                 "-" + str(row.getValue(field_desc)) + ".pdf")
    del mxd
except Exception as e:
    print (str(e))

ddpPDFs= glob.glob(cwd+"/../Exports/*.pdf")

for pdf in ddpPDFs:
    print os.path.basename(pdf)

#Update the properties of the final pdf to show thumbnail view
for pdf in range(0,len(ddpPDFs)):

del finalPdf

if os.path.exists(finalpdf_filename):
    print ("DDP pages created")
    print("Error creating the "+data_name+" PDF book. Please check code")