In this article you will learn how to convert your ArcMap MXD files to image files (JPG, JPEG, PNG, TIFF, GIF, among others) using Python. Of all the existing image formats you will learn how to convert to PNG format as it has an optimal balance between file size and image quality.
This will help your productivity because as you develop a geographic information system you tend to generate several graphical outputs to present in text documents, as an example let's suppose you and I have 500 graphical outputs, in case of a change in any element within the spatial database and it is necessary to update these graphical outputs the normal solution would be:
How to export an MXD to PNG
1) Open one of the MXD files.
2) Go to File.
3) Click “Export Map...” in the displayed submenu.
4) Choose the file name (a), the file type (b) and the resolution (c). Then press the “Save” button (d).
5) Repeat this procedure for each MXD file.
This procedure multiplied by 500 times can consume a lot of your valuable time, for that reason I will show you how it can be much more efficient using Python code (Don't worry you don't need to know how to program to do it).
How to export multiple MXD files within a folder using Python (ArcPy)
Step 1: Identify the path where the graphic outputs in MXD format are stored.
Step 2: Open ArcMap.
Step 3: Open the Python window in the Standard toolbar.
Step 4: Copy the following code into a notepad and replace the text C:\EJEMPLO\EJEMPLO in line #03 with the path to the folder identified in step 1.
#02
arcpy.env.workspace = ws = r"C:\EJEMPLO\EJEMPLO" #03
#04
mxd_list = arcpy.ListFiles("*.mxd") #05
#06
for mxd in mxd_list: #07
#08
current_mxd = arcpy.mapping.MapDocument(os.path.join(ws, mxd)) #09
pdf_name = mxd[:-4] + ".png" #10
arcpy.mapping.ExportToPNG(current_mxd, pdf_name,resolution=1000) #11
#12
del mxd_list #13
Step 5: Copy the modified code into the Python window and press the Enter key twice.
After a few seconds you will see the images in PNG format start to appear in the folder where the MXD files are stored and you can automatically export any number of these native ArcMap files.
Notes:
a) In line #11 you can modify the dpi with which the images are exported, currently it is set to 1000 dpi, which in my experience is the best resolution for image files to use in documents, The export time is directly proportional to the amount of dpi.
b) In line #11 you can modify the type of image file you want, replacing the text ExportToPNG by any of the following options ExportToBMP, ExportToEMF, ExportToEPS, ExportToGIF, ExportToJPEG, ExportToSVG, ExportToTIFF; it is also necessary to modify in line #10 the text .png by the desired output format (.bmp, .emf, .eps, .gif, .jpg, .svg, .tif) .
I hope you enjoyed this article, soon I will upload a video explaining the procedure that you can consult in this blog. Save my blog among your favorite links, I will be uploading many more tricks of this style, remember that you can send me your concerns in the contact page or leave your comment, I will be attentive to respond.




