I'm attempting to writing a python script that will automate exporting a set of stock maps to JPEG from their mxd files, and I'm having some strange issues getting there.

I've alternatively been getting a Visual C++ Runtime error saying python experienced an abnormal program termination, or the program throws an exception saying "AttributeError: PageLayoutObject: Error in executing ExportToJPEG"

I've tried two main ways of running this process. In one I loop through an array of directories and pull the individual mxd files into the export command, as below:

for line in Direct:
    path = str(line) + "*.mxd"

    listing = os.listdir(path)
    for infile in glob.glob(path):
        mxd = arcpy.mapping.MapDocument(infile)
        infile = infile.split("\\")[-1]
        infile = infile.rstrip('.mxd')
        infile = infile + ".jpg"

        project = os.path.join(destpath, infile)
        arcpy.mapping.ExportToJPEG(mxd, project, resolution = 200)

        del mxd

In the other form, I copy the arcpy.mapping.ExportToJPEG() line over and over with the parameters for each map specified, as below:

mxd = arcpy.mapping.MapDocument(r"Y:\Maps\map1.mxd")
project = "C:/Maps/map1.jpg"
arcpy.mapping.ExportToJPEG(mxd, project, resolution = 200)

mxd = arcpy.mapping.MapDocument(r"Y:\Maps\map2.mxd")
project = "C:/Maps/map2.jpg"
arcpy.mapping.ExportToJPEG(mxd, project, resolution = 200)

mxd = arcpy.mapping.MapDocument(r"Y:\Maps\map3.mxd")
project = "C:/Maps/map3.jpg"
arcpy.mapping.ExportToJPEG(mxd, project, resolution = 200)

I've tried multiple tests to see if my syntax is wrong, and if the script is using too many resources and crashing, but haven't been able to figure out what my issue is.

The weird part is I can't seem to find any pattern or reason to the maps I'm getting these errors on. It seems like it changes every time I alter my script.

  • Today, I also meet this trouble.I try to repair this arcgis desktop.it was maybe others Python page influence.
    – Xilin Ji
    Commented Dec 15, 2017 at 1:42
  • how did you fix it?
    – pnkjmndhl
    Commented Feb 7, 2020 at 18:05

8 Answers 8


This is old but I had the same error "PageLayoutObject: Error in executing ExportToJPEG". The problem for me was that I was trying to write to a folder that didn't exist. Once I created the folder, it worked fine. This also makes me think that if you had some other kind of permissions problem that didn't let you write to the output file it might also be expressed as this kind of an error.


You need to include empty quotes for parameters you aren't changing. Since resolution is the 6th parameter, you shouldn't place it directly after parameter 2 (out_jpeg). The empty quotes are place markers.

Example: arcpy.mapping.ExportToJPEG(mxd, project, "", "", "", resolution = 200)

You don't need to put quotes in for parameters after the last one you have defined.

Python isn't smart enough to figure out the order of parameters without explicitly telling it what is what. In your case, Python throws an error because you are defining parameter 6 in parameter 3's location.

Edit: I did some research and learned that you don't need to put in parameter space fillers if you explicitly state the parameter name in your code. I.e., since you put "resolution = 200" instead of just "200", Python should be able to figure out which parameter you are talking about. It shouldn't hurt to put in the empty quotes, but it isn't necessary if you explicitly state your parameter. That's why your original code was working fine.

Something you may test is explicitly adding default optional parameters to see if that works. For example,

arcpy.mapping.ExportToJPEG(mxd, project, data_frame = "PAGE_LAYOUT", resolution = 300)

worked on my machine. I'm not sure why the code works with some mxds and not others. My guess is that some mxds don't like the parameter syntax for some reason. Sorry I couldn't help more. Maybe some Python gurus can chime in.

  • This makes sense, but it's giving me the error after working fine on 10 or more maps already. Let's find out if it works! Commented Oct 16, 2012 at 16:52
  • 3
    I don't have an explanation for that. I'm just giving a possible explanation for why you are getting the specific error you mentioned in your OP. Why it didn't have a problem with it before is beyond me. ESRI software is somewhat notorious for random bizarre effects. Have you changed ArcGIS versions recently?
    – Baltok
    Commented Oct 16, 2012 at 16:56
  • When I added tbe empty quotes to the script it actually gave me this exception: "AttributeError: PageLayoutObject: Error in parsing arguments for ExportToJPEG" I dunno what to do with that... As far as changing versions recently, I upgraded to 10.1 when it came out a few months ago. Commented Oct 18, 2012 at 15:42
  • Well, I did some testing on my ArcGIS 10.0 machine and I get the same error you do. I don't know why it has a problem with the double quotes considering ESRI specifically mentions you can use it in their Python help. Also, I goofed a little on my original answer. See above edits.
    – Baltok
    Commented Oct 18, 2012 at 18:25
  • "Python isn't smart enough to figure out the order of parameters without explicitly telling it what is what." No, this has nothing to do with Python's "smarts." The problem is with the design of the ExportToJPEG() function: it probably should let some of its inputs be optional keyword arguments instead of requiring empty strings.
    – sgillies
    Commented May 17, 2016 at 15:30

Try this code:

import arcpy,os,sys
import arcpy.mapping
from arcpy import env

env.workspace = r"C:\Project"
for mxd in arcpy.ListFiles("*.mxd"):
    print mxd # print list of mxd's in the folder
    mapdoc = arcpy.mapping.MapDocument(r"C:\Project\\" + mxd)
    df = arcpy.mapping.ListDataFrames(mapdoc, "Layers")[0]
    arcpy.mapping.ExportToJPEG(mapdoc,r"C:\Project\out\\"+os.path.basename(mapdoc.filePath).replace ('.mxd','') +".jpg")
    print 'ExportToJPEG'
del mxd
import arcpy, os
import arcpy.mapping

PATH = r"D:\test" ## Path with the mxds
arcpy.env.workspace = PATH

listMXD = arcpy.ListFiles("*.mxd")
for item in listMXD:
    mxd = arcpy.mapping.MapDocument(os.path.join(PATH, item))
    outjpg = item[:-4] + ".jpj"
    arcpy.mapping.ExportToJPEG(mxd, outjpg, resolution=300 )
del mxd
  • 3
    Some context or additional information about why this code works or works better would improve the quality of this answer.
    – Chris W
    Commented Nov 10, 2015 at 20:21

It doesn't seem any of the answers above answered the question, even though each may contain some useful information.

This could be a memory issue. mxd and df could take up huge memories, especially if any huge datasets are involved. When looping through a lot of mxds to export, promptly clear temporary mxds and dfs would be necessary, such as

del mxd

del df

within each loop.


To anyone who stumbles on this issue: I was receiving this error, but I'm having trouble reproducing it. My mxd file was on a network and used shp files on a network. I quit ArcMap, reopened it, and then tried ExportToPDF from an mxd on my C drive that referenced one shp file, also on my C drive. I was able to export a pdf to my C drive. From there, I added complexity:

  • referencing a shp file on the network
  • using an mxd on the network
  • and finally exporting to the network.

I was able to export successfully in all of those cases. I have two theories about where the error came from:

  1. My pdf file path was wrong. I'm fairly new to python, and it wouldn't surprise me if I messed up the "\", "\", and "/" at some point. Starting with exporting to a simple file path on the C drive helped with the troubleshooting.

  2. As was stated elsewhere, memory could have been the issue. I did not del the MapDocument while I was debugging, so there was probably a lot of memory used up from that. So try deleting the MapDocument and see if that helps

Sorry I can't solve the problem. In my case, I started simple, gradually added complexity, and the problem was removed.


This problem is also caused by changing the version of ArcGIS desktop. I was using ArcMap 10.6 and I had no issues with exporting the jpg file. Recently, I upgraded my ArcGIS to 10.7. Now, its not that the python code does not work. But, every time I open the mxd file try to modify it (even the slightest, like, saving it without even changing anything), I get this error.

"AttributeError: PageLayoutObject: Error in executing ExportToJPEG"

The old mxd file saved with the earlier version still works.


It is probably a memory issue. Remember that each time your program executes the line:

mxd = arcpy.mapping.MapDocument(infile)

it creates a map document and then assigns the name "mxd" to it. So after executing that line 10 times, you will have 10 of these memory-intensive objects. So as others point out, the problem should resolve with

del mxd
del df 
#  optionally add:  gc.collect()

at the end of each loop. But when I have tried this recently on a project needing a map for almost every county, the memory kept increasing. If I set resolution to 300, the program would fail after about 10 maps; if I set it to 96, it failed after about 100 maps.

So I ended up just putting the key two lines of code:

mxd = arcpy.mapping.MapDocument(mxd_source) 
arcpy.mapping.ExportToJPEG(mxd, output_map_jpg, resolution=jpg_resolution)

into a small subprocess and calling the subprocess for each map.

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.