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.
Many map books include ancillary, or supporting, documents. These can be report text, tables, indexes, and other supporting data. Creating these types of map books can be done through a combination of ArcMap Data Driven Pages and an arcpy.mapping Python script.
The example above shows a topographic map book for Arenac County, Michigan. This map book includes a number of supporting pages offering text information, graphs, and tabular data. 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.
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 PDF files containing reports and graphs.
- You have an existing PDF file for the map book title page.
- You have an existing PDF file containing the overview map page.
Since the map book displays page numbers, you should make sure that the page numbers Data Driven Pages are using account for the supporting pages that you will insert into the map book. For example, here is a view of the Data Driven Pages index layer table. PageNumber was created and populated by the Grid_Index_Features geoprocessing tool when the grid was created. These page numbers will not be correct since you will be inserting pages between the map pages. A new field needs to be created for page numbers and the values must be populated accordingly. Here a new field, New PageNum, was created and populated with values that account for the pages to be inserted.
Make sure that you choose the correct field for the page number field before creating the Data Driven Pages.
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.
Insert supporting pages into a map book PDF.
import arcpy, os # Create an output location variable outDir = r"C:\temp\MBExample\final_output" # Create a new, empty pdf document in the specified output location folder finalpdf_filename = outDir + r"\ArenacMB.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 overview 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 Reports.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) # Insert the pdf pages containing the reports and graphs into the final pdf # finalPdf.insertPages(r"C:\temp\MBExample\ancillary_pages\Report_pg4.pdf", 4) finalPdf.insertPages(r"C:\temp\MBExample\ancillary_pages\Report_pg5.pdf", 5) finalPdf.insertPages(r"C:\temp\MBExample\ancillary_pages\Report_pg7.pdf", 7) # 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
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.
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 map document is ArenacDDP Reports.
Next, insert the PDF pages containing the reports and graphs into the final PDF.
Finally, the code updates the properties, then saves and closes the final PDF.