dhofer

Export mxd's and Data Driven Pages to PDF

Discussion created by dhofer on Dec 21, 2011
Latest reply on Dec 29, 2011 by jbarrette-esristaff
Hi,

I got this code below from
http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=3EA2A85B-1422-2418-7F00-29AE1A98253F

It works great.  But I need it to not combine the pdfs.  I'm not a pythoner yet.  Could someone help me modify this code.  Thanks
Daniel Hofer



import arcpy, os

path = os.curdir
PDFDir = os.path.join(os.curdir, "PDFs")

def ExportToPDF (fileName):

    if not os.path.exists(PDFDir):
        os.mkdir(PDFDir);
   
    OutputPDFPath = os.path.join(PDFDir, fileName.replace(".mxd", ".pdf"))
    if os.path.exists(OutputPDFPath):
        os.remove(OutputPDFPath)

    mxd = arcpy.mapping.MapDocument(fileName)
   
    if (hasattr(mxd, 'dataDrivenPages')):
        outPDF = arcpy.mapping.PDFDocumentCreate(OutputPDFPath)

        for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
            mxd.dataDrivenPages.currentPageID = pageNum           
            arcpy.mapping.ExportToPDF(mxd, os.path.join(PDFDir, "Temp.pdf"))
            outPDF.appendPages(os.path.join(PDFDir, "Temp.pdf"))
            os.remove(os.path.join(PDFDir, "Temp.pdf"))               
            print pageNum
        del outPDF
       
    else:
        arcpy.mapping.ExportToPDF(mxd, OutputPDFPath)
   
    print OutputPDFPath
    return True

print path
for subdir, dirs, files in os.walk(path):
    for file in files:
        if (file.endswith(".mxd") == True):
            ExportToPDF (file)

Outcomes