Select to view content in your preferred language

ExportToPDF Batch

774
2
07-19-2011 08:02 AM
JoeNunn
Frequent Contributor
Hi - done a script to batch process multiple MXDs and I get this error:
Runtime error <type 'exceptions.AttributeError'>: PageLayoutObject: Error in executing ExportToPDF

The error seems to be due to the PDF string 'pdfname' as if I put r'C:\\temp\\test.pdf') directly in the ExportToPDF function (not in the string though!) it works. Whats the problem?

Here is the script:

import glob, arcpy, os

mxdlist = glob.glob('T:\\45\\4588 EIA (London)\\Graphics\\GrDOCS\\Reports_5211\\ES\\*.mxd')

for mxd in mxdlist:
    m = os.path.basename(mxd)
    basename, ext = os.path.splitext(m)
    mxdproper = arcpy.mapping.MapDocument(mxd)
    print mxd
    print basename
    pdfname =  r"%s%s%s" % (r"T:\\45\\4588 EIA(London)\\Graphics\\GrDOCS\\Reports_5211\\ES\\",basename, r".pdf")
    print pdfname
    arcpy.mapping.ExportToPDF(mxdproper, pdfname)
    del mxd
Tags (2)
0 Kudos
2 Replies
BruceNielsen
Frequent Contributor
It might be your combination of using the 'r' to denote a raw string with the double backslashes. Try replacing:
pdfname =  r"%s%s%s" % (r"T:\\45\\4588 EIA(London)\\Graphics\\GrDOCS\\Reports_5211\\ES\\",basename, r".pdf")
with
pdfname = os.path.join("T:\\45\\4588 EIA(London)\\Graphics\\GrDOCS\\Reports_5211\\ES\\", basename+".pdf")
0 Kudos
JoeNunn
Frequent Contributor
Thanks Bruce - that has fixed it!
0 Kudos