I'm experiencing differences from exporting features to PDF from within ArcMap and using a stand alone python program. Basically, I'm selecting a feature from a layer, zooming to the selected extent, changing the scale of the dataframe, and exporting the image to a pdf from PAGE_LAYOUT view- something pretty simple.

The issue that I'm having is that from within ArcMap, everything works fine. In the page layout view, everything looks as expected, and once exported, it looks great.

I'm trying to automate this so after building a stand alone python program, it exports like it's supposed to, however the scale is off by about 200.0.

Here's a snippet of my code:

mxd = arcpy.mapping.MapDocument("C:\Path\To\MxdFile.mxd")
dataFrames = arcpy.mapping.ListDataFrames(mxd)
df = dataFrames[0]

layers = arcpy.mapping.ListLayers(mxd, "*", df)
for layer in layers:
    if layer.name == "LayerIWantToUse":

if layer.name != "LayerIWantToUse":
    raise Exception("Cannot find layer.")

arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")

query = "OBJECTID = 1"
layer.definitionQuery = query
arcpy.SelectLayerByAttribute_management(layer,"NEW_SELECTION", query)

df.scale = 2400.0
fileName = r"Python_2400.pdf")
arcpy.mapping.ExportToPDF(mxd, fileName, "PAGE_LAYOUT", 1056, 1632)

The scale that it actually exports, appears to be 1:2200, instead of 1:2400 like it's supposed to. I've attached both images to show the differences.

I have noticed that if I save the MXD with a different scale (1:100000 for example) and with ArcMap in "Data View", I have the scale issues. If I make sure "Layout View" is selected, change the scale to 1:2400, and save the MXD, I do not have the scale issues within python/arcpy.

I've seen a couple forum posts regarding something similar, some saying it's a bug that should have been fixed in 10.1, but a) I'm on 10.2.1, and b) no explanations on what could be causing it. Another post recommended that if you change the extent/scale twice, and then export the image/pdf twice, it might fix itself, but that solution didn't work for me either.

Has anyone else encountered something similar, and if so do you have any recommendations?

1 Answer 1


You might notice that when you manually change between Data View and Layout view, the scale changes.

I would suggest changing to Layout view before you set the scale i.e. something like:

df.scale = 2400.0
  • 1
    That is a very common issue. Great suggestion! Commented Oct 16, 2014 at 14:17
  • 1
    @Dan_h_b - After some quick testing, I believe this is the functionality I was missing. If further testing changes, I'll update my original question. Marking this as answered - thank you!
    – Qorey
    Commented Oct 17, 2014 at 14:47
  • 1
    @Qorey that's great news. If you find the scale doesn't change, you might just need to add this to the end of the script after changing to the layout view and setting the scale: arcpy.RefreshActiveView()
    – Dan_h_b
    Commented Oct 17, 2014 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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