English

FAQ: Is it possible to export Data Driven Pages based on the page name?

Question

Is it possible to export Data Driven Pages based on the page name?

Answer

When using Data Driven Pages to export a map document to file formats such as PDF, PNG, or JPEG, the conventional way of naming the generated output files is by page number. However, it is also possible to create the output pages according to the page name. This is set in the ArcMap layout view before exporting.

Use the following sample Python script as a guide when exporting Data Driven Pages based on a field to name the output files:

mxd = arcpy.mapping.MapDocument("CURRENT")  
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):  
 mxd.dataDrivenPages.currentPageID = pageNum  
 pageName = mxd.dataDrivenPages.pageRow.ZIP_CODE
 pageName = pageName.replace("/", "_")
 pageName = pageName.replace(" ", "")  
 arcpy.mapping.ExportToPNG(mxd, r"C:\Users\username\Documents\ArcGIS" + pageName + ".png")  
del mxd

In the code above, the output pages are created using the ZIP_CODE field as the file name, as seen in line 4. Change the field name accordingly to uniquely identify each file with the page name. If the name contains special characters or spaces (which are not allowed when naming files), use the replace() method to replace the characters with underscores and remove spaces - as seen in lines 5 and 6 respectively.

In line 7, the ExportToPNG ArcPy function is used to export Data Driven Pages to the PNG image format. Change the function to generate the output files, depending on the desired format. For more information on the ArcPy functions supported when exporting Data Driven Pages, refer to ArcGIS for Desktop Help: Exporting and Printing Maps. It is required to specify the path to store the output files and the respective extension of the file format to allow the files to be generated in the specified format.

Related Information