Exporting all Map Series pages to PDF with page name as output file name using ArcPy

I am trying to export all of my current map series pages into multiple PDFs with the Page Name as the file name. So, "PAGENAME.pdf". Currently, the code runs, but no output is given. I have looked around at other documentation and it doesn't seem to help in my instance. The output is not producing any PDFs at the moment but there are map series records in the project!

 import arcpy, os, sys aprx = arcpy.mp.ArcGISProject(r"\My Documents\20-0181 - Map Edits.aprx") outpath = (r"\My Documents\Phase 7 Data") l = p.listLayouts()[0] if not l.mapSeries is None: ms = l.mapSeries if ms.enabled: for pageNum in range(1, ms.pageCount + 1): ms.currentPageNumber = pageNum print("Exporting ".format(ms.pageRow.CCTVLines_Select_FACILITYID)) pageName = ms.pageRow.CCTVLines_Select_FACILITYID l.exportToPDF(outpath + ".pdf") 
65.3k 29 29 gold badges 112 112 silver badges 343 343 bronze badges asked Jul 16, 2020 at 21:36 David Nilges David Nilges 21 2 2 bronze badges

I have some arcpy desktop code that might help, its purpose was to export a sample of a very large series by page number mod divisor. It may be too different to ArcGIS PRO to be of any use though. I do notice that you're not embedding the pageName into your output, are you missing a .format. this part is python not data driven pages. Use os.join instead of outpath + as the intermediate \\ is missing, this means the output will always be \My Documents\Phase 7 Data.pdf; are you using Windows? That's not a valid directory/file path as the drive is missing.

Commented Jul 17, 2020 at 0:15

it looks like you're trying to use string formatting here, try l.exportToPDF(outpath + r"\<0>.pdf".format(ms.pageRow.STATE_NAME))

Commented Jul 17, 2020 at 0:27

If outputing to your My Documents folder this can be derived using os.path.join(os.environ.get('USERPROFILE'),'Documents') on Windows making outpath = os.path.join(os.environ.get('USERPROFILE'),'Documents','Phase 7 Data'). The USERPROFILE system variable has existed on Windows since NT and I don't think it will go away any time soon making your code potentially forward compatible and backward compatible; I don't know about Windows 3.1 as I was using UNIX at the time and DOS on PCs, I only shifted to Windows around 1997 with NT. Note that the user profile is dependent on the logged in user.