Select to view content in your preferred language

Data Driven Pages: Page names in Adobe / Python

417
1
04-06-2012 07:10 AM
JustinWolff
Regular Contributor
When using data driven pages, is there a way to use python to control the individual page names as they appear in the table of contents in Adobe?  By default they begin 1, 2, 3...  I'd like them to appear in Adobe using the index page name.  I am currently using ddp to create multi-page .pdf map books, but then using Adobe to rename each page to match the index name.

data.zip contains sample .pdf examples and index .shp

Any help would be greatly appreciated.  Thanks!
0 Kudos
1 Reply
JoelCalhoun
Deactivated User
I haven't tried this using a multi-page pdf just indivdual pdfs but I believe the results should be the same.

If you want to name your pdf page from an attribute in your index grid then ESRI has provided a way.
With Data Driven Pages you can access any attribute value in your index grid for the active page.

My atlas uses a modified PLSS grid sorted by Township, Range, Section, and Quarter Section.
I added an attribute to the index grid called Page_Num with values from 1 to the number of pages based on the TRSQ sort (smallest to largest).
I use this Page_Num to get the internal DDP ID number.
This internal page ID number is what you use to set the current map page.
Then you use  mxd.dataDrivenPages.pageRow.(fieldname)  to pull the attribute value you want from the selected index page.
Once you have the attribute name you can plug it into the export string as your pdf name.

Here is some sample code from my script.
This is just a snippit from a much larger process that builds several different atlases from several different index grids.
Earlier in the process I build a page list from the current index grid.
The following code uses that page list to cycle through the current index grid, grabbing the TRSQ attribute and exporting the active map page with that as part of the name.
mxd = arcpy.mapping.MapDocument(r"X:\assr\carto\maps\Work_Map_Atlases\Residential_Atlases\Cycle_" + cycle_num + "_Atlas_temp.mxd")
for page in Page_List:                                                                 # Loop through Page_List
       Pg_Num =str(page)                                                             # Page number from Page_List
       pageID = mxd.dataDrivenPages.getPageIDFromName(Pg_Num)    # Using the page number, get the pageID for the MXD
       mxd.dataDrivenPages.currentPageID = pageID                         # Set the current page in the DDP atlas to the pageID
       fieldValue_str = str(mxd.dataDrivenPages.pageRow.TRSQ)         # Pull the TRSQ field info from the active Index page
       pageID_str = str(pageID)                                                    # Convert pageID to a string to use in the PDF output name string
       arcpy.mapping.ExportToPDF(mxd, folder_path + folder_name + "\\" + benchmark_folder_yr + "_" + I + "\\" + fieldValue_str + "_" + pageID_str + ".pdf", "PAGE_LAYOUT")



I hope that points you in the right direction.



Joel



*EDIT*

After checking your examples and rereading your request, I'm not sure that what I have provided will solve your issue.  I don't see a difference between the two PDFs you have provided.  Also, I'm not sure exactly what you mean by Table of Contents in Adobe.  Maybe there is a list I'm not seeing but in the Thumbnail List, I'm not sure if you can control that shows up there.  It seems to me that that those are just the internal page numbers for the pdf and may not be related to the actual pdf names that were used to create it.  In the "Layers" list, the name that shows up seems to be the name of each pdf and in that case, what I have provide would allow you to change that but those values seem the same between both the Regular and Preferred PDFs you provided.  Perhaps a little more clarity would shed some light on this.
0 Kudos