Select to view content in your preferred language

arcpy.mapping.ExportToPDF frustrating me to no end!

6780
11
04-30-2013 05:48 PM
ThomasColson
MVP Alum
I have this long-running, works like clockwork py script, which I decided to snip a few lines from to do one-off map exports to PDF:

for pgNumLeft in range(1, tempDDPLeft.pageCount + 1, 2):
  temp_filename = r"X:\GIS_Projects\1205_Map_Book\MB_" + \
                            str(pgNumLeft) + ".pdf"
  if os.path.exists(temp_filename):
    os.remove(temp_filename)
  tempDDPLeft.exportToPDF(temp_filename, "RANGE", pgNumLeft, "PDF_SINGLE_FILE", "720","BEST","CMYK","NONE","NONE","VECTORIZE_BITMAP", "FALSE","TRUE", "LAYERS_ONLY", "FALSE")


So I try, as per the example at http://resources.arcgis.com/en/help/main/10.1/index.html#/ExportToPDF/00s300000027000000/:

import arcpy, os
mxd = arcpy.mapping.MapDocument(r"X:\GIS_Final\data\basedata\basemap\Maps\ArcGIS\Blockhouse\Blockhouse.mxd")
arcpy.mapping.ExportToPDF(mxd, r"X:\GIS_Final\data\basedata\basemap\Maps\ArcGIS\Blockhouse\Blockhouse.pdf")
del mxd


which returns:

Traceback (most recent call last):
  File "C:/Temp/TopoMaps.py", line 3, in <module>
    arcpy.mapping.ExportToPDF(mxd, r"X:\GIS_Final\data\basedata\basemap\Maps\ArcGIS\Blockhouse\Blockhouse.pdf")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\mapping.py", line 1139, in ExportToPDF
    layout.exportToPDF(*args)
AttributeError: 'NoneType' object has no attribute 'exportToPDF'



Adding:

arcpy.mapping.ExportToPDF(mxd, r"X:\GIS_Final\data\basedata\basemap\Maps\ArcGIS\Blockhouse\Blockhouse.pdf", "PAGE_LAYOUT")


...same error. However, the same line interestingly works in the ArcMap Python Window (I'm trying this in the Python GUI).

So I try

arcpy.mapping.ExportToPDF(mxd, r"X:\GIS_Final\data\basedata\basemap\Maps\ArcGIS\Blockhouse\Blockhouse.pdf", "PAGE_LAYOUT", 720, "BEST", "CMYK", "FALSE", "NONE", "VECTORIZE_BITMAP", "FALSE" , "TRUE", "NONE", "FALSE") 


Which returns

Traceback (most recent call last):
  File "C:/Temp/TopoMaps.py", line 3, in <module>
    arcpy.mapping.ExportToPDF(mxd, r"X:\GIS_Final\data\basedata\basemap\Maps\ArcGIS\Blockhouse\Blockhouse.pdf", "PAGE_LAYOUT", 720, "BEST", "CMYK", "FALSE", "NONE", "VECTORIZE_BITMAP", "FALSE" , "TRUE", "NONE", "FALSE")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 153, in fn_
    arg_name].keys())))
ValueError: Invalid value for image_quality: 'FALSE' (choices are: ['BETTER', 'FASTEST', 'FASTER', 'BEST', 'NORMAL'])
>>>


...and many, many, many permutations of variables in many, many, many permutations of where they should go, all with a varation of
Invalid value for  ...
.


What is frustrating is that I followed the ESRI example for data-driven page export to PDF, and the syntax in the online-documentation worked, however, the example for exporttopdf is misleading.

map has 2 DF's, 10.1 SP1
Tags (2)
0 Kudos
11 Replies
RhettZufelt
MVP Notable Contributor
I have had the same error with the exportToJpeg tool when I was trying to assign an invalid filename ( 100-B/C.jpg ).  It didn't like the slash in the filename and give me the NoneType error.

Doesn't appear as if this is the case here......

R_
0 Kudos
AaronCraig2
Regular Contributor

Sorry to revive this old dead thread, but I was recently having this problem. Turns out it was caused by mxd's saved in different ArcGIS desktop versions. 

I successfully upgraded from ArcMap 10.3 to 10.5. I saved my MXD from 10.3 using 10.5 (thereby making it an 10.5 mxd). Ran my python script: NO PROBLEMS.


Other issues came up with 3rd party extensions, so I reverted back to 10.3. Now when attempting to run my python script I get the same error as above.

Found old versions of the same MXD and attempted to run my python script: NO PROBLEMS.

Reloaded ArcMap 10.5, saved each document as a 10.3 mxd again, reran my python script: NO PROBLEMS.

Definitely an mxd versioning problem with arcpy.