I'm trying to write a python script that will export multiple MXDs to individual PDFs while using a feature class field to rename the pdfs (this can be an optional field, if not check it can copy the mxd file name). I copied a script from ESRI, just need the renaming of pdfs part to work.

import arcpy, os, string

#Read input parameters from script tool
mxdList = string.split(arcpy.GetParameterAsText(0), ";")
outPDFpath = arcpy.GetParameterAsText(1)

#Create a new PDF object to store the results
outputPDF = arcpy.mapping.PDFDocumentCreate(outPDFpath)

Try this out

dpi = 300
quality = "BEST"
for item in mxdList:
    mxd = arcpy.mapping.MapDocument(item)
    outpdf = item.split('.')[0] + ".pdf"
    arcpy.mapping.ExportToPDF(mxd, outpdf, "", 0, 0, dpi, quality)
| improve this answer | |

is there a question here? I am guessing that this code does not work? You aren't doing anything with the list objects to use them as pdf names. you'll have to use some for loop to get each file name from the list:

 for item in mxdList:
    outputPDF = arcpy.mapping.PDFDocumentCreate(outPDFpath + "\" + item)

That is just hacked together off the top of my head. Try something similar.

for os.path.join you might try

outputPDF = arcpy.mapping.PDFDocumentCreate(os.path.join(outPDFpath, item))
| improve this answer | |
  • Try using os.path.join instead of string concatenation. Also the second outputPDF is probably supposed to be outputPDFpath. – blah238 Jan 8 '14 at 16:22
  • @blah238 updated per your comments – Barrett Jan 8 '14 at 16:33
  • Oh I meant outPDFpath. Anyways, we need to know what the real question is. – blah238 Jan 8 '14 at 16:37
  • he does state that he needs to get the renaming part to work. But, overall, the question does seem a bit abrupt – Barrett Jan 8 '14 at 16:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.