AnsweredAssumed Answered

Python script in export pdf with fieldname

Question asked by jarale on Oct 12, 2018
Latest reply on Oct 15, 2018 by Dan_Patterson

Hi, I have the script below. I am trying to export 400 pdfs with the fieldname "Label" but it only export the last page of pdf. What goes wrong ?

 

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")

pageNameField = "Label" 

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):

        mxd.dataDrivenPages.currentPageID = pageNum

pageName = mxd.dataDrivenPages.pageRow.getValue(pageNameField)

pageName = pageName.replace("/", "_")

pageName = pageName.replace(" ", "")

print "Exporting page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))

mxd.dataDrivenPages.refresh()

 

arcpy.mapping.ExportToPDF(mxd, r"C:\TEST\181013_test" + str(pageName) + ".pdf")

del mxd

Outcomes