PYTHON GIS - How to export a MXD (Batch) to PDF with Python

0

 


In this article you will learn how to convert your ArcMap (ArcGIS) MXD files stored in a folder to portable document format (PDF) that allows the consumption of maps to users outside the geographic information systems using Python.


This will help in your productivity because as you develop a geographic information system tends to generate several maps either to accompany the results of a study and / or field exploration, as an example let's say you and I are 500 maps, in case of a change in any element within the spatial database and it is necessary to update these maps the normal solution would be:



How to export a MXD to PDF


1) Open one of the MXD files.


2) Go to File.


Muestra la ubicación del botón File en el menú principal de ArcMap


3) Click on “Export Map...” in the displayed submenu.


Muestra la ubicación del botón Export Map dentro del submenú File que a su vez se ubica en el menú principal

 


4) Choose the file name (a), the file type (b) and the resolution (c). Then press the “Save” button (d).  


Muestra las opciones a ajustar a la hora de exportar un archivo MXD a PDF de forma manual



5) Repeat this procedure for each MXD file.


This procedure multiplied by 500 times can consume a lot of your valuable time, so 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 batch export MXD to PDF files?


Step 1: Identify the path where the MXD graphic outputs are stored.


Step 2: Open ArcMap.


Step 3: Open the Python window in the Standard toolbar.


Muestra la ubicación de la ventana Python dentro de la barra de herramientas Standard (estándar)


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.



import arcpy, os                                                      #01
                                                                      #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] + ".pdf"                                      #10
    arcpy.mapping.ExportToPDF(current_mxd, pdf_name,resolution=300)   #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 PDF files 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 PDF files are exported, currently it is set to 300 dpi, which according to my experience is the best resolution for PDF files considering an ISO B1 paper size (707 x 1000 mm), The export time is directly proportional to the amount of dpi.


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.


You may like these posts

No comments