Select to view content in your preferred language

Batch export to pdf for map series

2328
3
12-21-2022 06:57 AM
Labels (1)
JeremiahMcDonald
Emerging Contributor

I am trying to automate "Export to PDF" when using map series in ArcGis Pro. I have a project that contains a few layouts, some are a series, some are not. What I am trying to accomplish is export each page as it's own pdf if a map series is enabled in a layout. Please see below snippet. 

JeremiahMcDonald_0-1671634419119.png

This works to some degree, it exports the layouts that have a map series enabled but it only exports the first page of the series. I need it to export all pages as individual .pdf's. Any help would be much appreciated, thank you. I have also attached the code to a txt file, hope it helps. 

Sincerely,
Jeremiah McDonald
0 Kudos
3 Replies
JeffBarrette
Esri Regular Contributor

Hi Jeremiah,

The reason you are only getting one page instead of all pages is because you are exporting the Layout, not the MapSeries object.  Here is some code to do what you might need.

p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('*MS')[0]
ms = lyt.mapSeries
ms.exportToPDF(r"C:\Temp\OutName.pdf", 'ALL',multiple_files='PDF_MULTIPLE_FILES_PAGE_NAME')

 

JeremiahMcDonald
Emerging Contributor

It does not like the ('*MS')[0]. 

throws a index out of range error. Is this some kind of wildcard?

Sincerely,
Jeremiah McDonald
0 Kudos
JeffBarrette
Esri Regular Contributor

Jeremiah,

That is because I have a layout with a map series in a project that ends with the characters 'MS'.  For listLayouts, the first parameter takes the layout name or a wildcard '*' combined with characters that will return a unique name.

Arcpy.mp can be really powerful once you get the hang of it.  Here is a tutorial that might help you get a better understanding.

https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/tutorial-getting-started-with-arcpy-mp.htm

Jeff - Layout and arcpy.mp teams