Adding title and overview map pages to your map book
ArcGIS provides all the tools you need to create map books in printed or Adobe PDF format. A map book is a collection of pages printed or exported together. Many of the pages contain maps, but other pages may be dedicated to text, tabular information, tables of contents, or title pages and other content.
A more complete map book includes a title page and an overview map page. You can accomplish this through a combination of ArcMap Data Driven Pages and a simple arcpy.mapping Python script.
The example above shows a topographic map book for Arenac County, Michigan. This map includes a title page and an overview map page. You can create this document using Data Driven Pages and an arcpy.mapping Python script.
For more information, see Creating Data Driven Pages.
This example has the following assumptions:
- You have an existing map document with Data Driven Pages enabled.
This code example works with the simple reference series map book example shown in Building map books with ArcGIS.You can re-create this map book by following the steps outlined in these help topics:
- You have an existing PDF file for the map book title page.
- You have an existing PDF file containing the overview map page.
You can create title and overview map pages using ArcMap. Just author the content for each page and export each to a separate PDF.
Since the map book displays page numbers, you should make sure that the starting page number for the Data Driven Pages accommodates all the pages of the final map book that precedes them. In this example, there are two pages that precede the map pages. Therefore, the map pages start with page 3. Make sure that 3 is the value for Starting Page Number in the Setup Data Driven Pages dialog box.
Also, make sure you are using the correct text elements if you are displaying page number. Do not use Data Driven Page with Count since the count is the total number of Data Driven Pages only. It does not include other pages, such as title or report pages, that you will be incorporating into the final map book. Instead use Data Driven Page Number and combine this dynamic text with static text showing the total number of pages, for example, Page <dyn type="page" property="number"/> of 26.
Once you have a map document and PDF files ready, you can run the code below to create your final map book PDF. You can run the code in the Python window or in a stand-alone Python application.
Though the specific code in this topic applies to the example map book above, you can also apply the procedures and tips presented here to your own map books.
This script exports a map book to PDF with title and overview pages added.
import arcpy, os # Create an output directory variable # outDir = r"C:\temp\MBExample\final_output" # Create a new, empty pdf document in the specified output directory # finalpdf_filename = outDir + r"\FinalMB.pdf" if os.path.exists(finalpdf_filename): os.remove(finalpdf_filename) finalPdf = arcpy.mapping.PDFDocumentCreate(finalpdf_filename) # Add the title page to the pdf # finalPdf.appendPages(r"C:\temp\MBExample\ancillary_pages\TitlePage.pdf") # Add the index map to the pdf # finalPdf.appendPages(r"C:\temp\MBExample\maps\IndexMap.pdf") # Export the Data Driven Pages to a temporary pdf and then add it to the # final pdf. Alternately, if your Data Driven Pages have already been # exported, simply append that document to the final pdf. # mxdPath = r"C:\temp\MBExample\maps\ArenacDDP.mxd" tempMap = arcpy.mapping.MapDocument(mxdPath) tempDDP = tempMap.dataDrivenPages temp_filename = r"C:\temp\MBExample\temp_pdfs\tempDDP.pdf" if os.path.exists(temp_filename): os.remove(temp_filename) tempDDP.exportToPDF(temp_filename, "ALL") finalPdf.appendPages(temp_filename) # Update the properties of the final pdf # finalPdf.updateDocProperties(pdf_open_view="USE_THUMBS", pdf_layout="SINGLE_PAGE") # Save your result # finalPdf.saveAndClose() # Delete variables # del finalPdf, tempMap, tempDDP
The first lines of code import the necessary modules; create an output location variable where the final map book PDF will be saved; and create a new, empty PDF document in the specified output location folder. This PDF is the final output for this script.
Programming languages, such as Python, treat a backslash (\) as an escape character. For instance, \n represents a line feed, and \t represents a tab. When specifying a path, a forward slash (/) can be used in place of a backslash. Two backslashes can be used instead of one to avoid a syntax error. A string literal can also be used by placing the letter r before a string containing a backslash so it is interpreted correctly.
For more information, see the PDFDocument class of arcpy.mapping.
The next lines of code add the title page and the overview map page to the final PDF. This example assumes that you have existing PDF documents that can be used for title and overview map pages.
The next step is to add the map pages. This requires that you have a map document with Data Driven Pages already enabled. In this example, that document is ArenacDDP.mxd.
Finally, the code updates the properties, then saves and closes the final PDF.