Select to view content in your preferred language

Export each page of a map series to individual PDF files

816
2
Jump to solution
12-07-2022 12:39 PM
AliciaShyu
Occasional Contributor

I've adapted the following script to export each page of a map series to individual PDF files but it exports the entire map series 50 times (number of pages) and updates each export name with the name of each page title.

The original script exports each page to PNG file ( MapSeries example 2) 

aprx = arcpy.mp.ArcGISProject(ProProject)
try:
    msLayout = aprx.listLayouts('Neighborhoods MapBook')[0]   ## the number in brackets is the number in the layout
    print ('Layout {}'.format(msLayout.name))
    if not msLayout.mapSeries is None:
        ms = msLayout.mapSeries
        ms.refresh()
        if ms.enabled:
            for pageNum in range(1, ms.pageCount + 1):
                ms.currentPageNumber = pageNum
                pageName = ms.pageRow.NHNAME
                ms.exportToPDF(os.path.join(OutFolder, f"NeighborhoodsMapBook_{ms.pageRow.NHNAME}.pdf"))
                print(ms.pageRow.NHNAME + ' exported')
            
except:
    message = arcpy.GetMessages()

 

 

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

MapSeries.exportToPdf() activates each page of the series and exports them into the same pdf. You do that process for each page.

What you want to do is activate each page, then export the layout.

 

aprx = arcpy.mp.ArcGISProject(ProProject)
try:
    msLayout = aprx.listLayouts('Neighborhoods MapBook')[0]   ## the number in brackets is the number in the layout
    print ('Layout {}'.format(msLayout.name))
    if not msLayout.mapSeries is None:
        ms = msLayout.mapSeries
        ms.refresh()
        if ms.enabled:
            for pageNum in range(1, ms.pageCount + 1):
                ms.currentPageNumber = pageNum
                pageName = ms.pageRow.NHNAME
                msLayout.exportToPDF(os.path.join(OutFolder, f"NeighborhoodsMapBook_{ms.pageRow.NHNAME}.pdf"))
                print(ms.pageRow.NHNAME + ' exported')
            
except:
    message = arcpy.GetMessages()

Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

MapSeries.exportToPdf() activates each page of the series and exports them into the same pdf. You do that process for each page.

What you want to do is activate each page, then export the layout.

 

aprx = arcpy.mp.ArcGISProject(ProProject)
try:
    msLayout = aprx.listLayouts('Neighborhoods MapBook')[0]   ## the number in brackets is the number in the layout
    print ('Layout {}'.format(msLayout.name))
    if not msLayout.mapSeries is None:
        ms = msLayout.mapSeries
        ms.refresh()
        if ms.enabled:
            for pageNum in range(1, ms.pageCount + 1):
                ms.currentPageNumber = pageNum
                pageName = ms.pageRow.NHNAME
                msLayout.exportToPDF(os.path.join(OutFolder, f"NeighborhoodsMapBook_{ms.pageRow.NHNAME}.pdf"))
                print(ms.pageRow.NHNAME + ' exported')
            
except:
    message = arcpy.GetMessages()

Have a great day!
Johannes
AliciaShyu
Occasional Contributor

Thanks Johannes!!

The script now exports each page but it stops at page 25

Map Series- ArcGIS Pro.png

Do you have any idea why it's doing that?

0 Kudos