Select to view content in your preferred language

arcpy.mapping.ExportToPDF frustrating me to no end!

6277
11
04-30-2013 05:48 PM
ThomasColson
MVP Frequent Contributor
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
ChrisPedrezuela
Frequent Contributor
I think you should post your entire code if possible.

Seems your incorrectly declaring variables and parameters based on your errors.

i.e your range is wrong having 3 values in it.

## for pgNumLeft in range(1, tempDDPLeft.pageCount + 1, 2):
0 Kudos
ThomasColson
MVP Frequent Contributor
Running this entire code:

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


Returns this error:

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'
0 Kudos
ChrisPedrezuela
Frequent Contributor
if you were only using these codes here, there shouldn't be any issues.

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
0 Kudos
ThomasColson
MVP Frequent Contributor

[/HR]I am ONLY using the code posted previously, with no other code, and it returns the error message. Perhaps this warrents a call to ESRI tech support?
0 Kudos
SamCoggins1
Occasional Contributor
I would try this for starters:

import arcpy, os

mapDoc = r"X:\GIS_Final\data\basedata\basemap\Maps\ArcGIS\Blockhouse\Blockhouse.mxd"
pdf = r"X:\GIS_Final\data\basedata\basemap\Maps\ArcGIS\Blockhouse\Blockhouse.pdf"

mxd = arcpy.mapping.MapDocument(mapDoc)
arcpy.mapping.ExportToPDF(mxd, pdf)
del mxd


I know I've just given variable names... After this go into the map document properties and copy the file location and paste into the mapDoc variable. I had the 'NoneType' error the other day and spent half an hour staring at it wondering what was wrong and then realised I'd missed a folder in the path.
0 Kudos
KevinGray
Emerging Contributor
Has there been a resolution to this issue.  I am getting the same error:

Traceback (most recent call last):
  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'
0 Kudos
JeffBarrette
Esri Regular Contributor
Not sure, never got an update after the last suggestion.  Can you export from the UI via File Export (to PDF)?  If it works from the UI and your code is as simple as the example post above, and it still doesn't work, I would suggest contacting Tech Support.

Jeff
0 Kudos
KevinGray
Emerging Contributor
Yes, I can export from the UI.  Tech support seems to the next step.  Thanks.
0 Kudos
T__WayneWhitley
Honored Contributor
...in your case, looks like the case is wrong in the method, should be 'ExportToPDF' not what was quoted in the error, 'exportToPDF'.


hmmm, I question why there is 'NoneType object' quoted in there too...make sure your mxd obj is set to something too.
0 Kudos