0

I need to pdf several mxds into their individual pdfs and am hoping there is a quicker way to accomplish that other than opening each file individually and exporting individually. Data Driven Pages is not an option as it will not work for what I am doing.

I found this question already asked here and downloaded the toolbox and script that matt wilkie shared but it is not working for me: Batch exporting MXD to PDF files using ArcGIS Desktop? With the original I was getting an "Error 000576: Script associated with this tool does not exist." Then I copied the script the link above takes you to and put it in a new notepad text file and did "Add Script" to the toolbox. After doing that I quit getting an "error" message. However, it runs and says it is done but there are no pdf files to be found. The first message is: "Executing: ExportFolder2PDF "input folder name" output folder name false"

Here is the script file with a couple modifications I made:

''' Export a folder of maps to PDFs at their Map Document set sizes Known to work ArcGIS 10.4.1 and Python 2.7.3 Adapted from work by @bteranUFA and @Guest Batch exporting MXD to PDF files using ArcGIS Desktop? License X/MIT; (c) 2017 Environment Yukon, Matt Wilkie '''

import os import glob import arcpy # Folder to look for MXDs in in_path = arcpy.GetParameterAsText(0) # Where to save output documents exportPath = arcpy.GetParameterAsText(1) if exportPath == '': exportPath = in_path overwrite = arcpy.GetParameter(2) arcpy.AddMessage('Overwrite: %s' % overwrite) # Set the PDF parameters as variables here: data_frame = 'PAGE_LAYOUT' df_export_width = 1920 df_export_height = 1200 resolution = '300' image_quality = 'BEST' colorspace = 'RGB' compress_vectors = 'True' image_compression = 'ADAPTIVE' picture_symbol = 'VECTORIZE_BITMAP' convert_markers = 'False' embed_fonts = 'True' layers_attributes = 'LAYERS_ONLY' georef_info = 'True' jpeg_compression_quality = 85 maps = glob.glob(os.path.join(in_path, '*.mxd')) def exportmap(mxdPath, exportPath): fname = os.path.split(mxdPath)[1] basename = os.path.splitext(fname)[0] newPDF = os.path.join(exportPath, basename + '.pdf') open(newPDF, 'w').close() arcpy.AddMessage('Reading: ' + m) mxd = arcpy.mapping.MapDocument(m) arcpy.AddMessage('Writing: ' + newPDF) arcpy.mapping.ExportToPDF(mxd, newPDF, data_frame, df_export_width, df_export_height, resolution, image_quality, colorspace, compress_vectors, image_compression, picture_symbol, convert_markers, embed_fonts, layers_attributes, georef_info, jpeg_compression_quality) del mxd return for m in maps: fname = os.path.split(m)[1] basename = os.path.splitext(fname)[0] newPDF = os.path.join(exportPath, basename + '.pdf') arcpy.AddMessage('--- %s' % os.path.split(m)[1]) if os.path.exists(newPDF): if overwrite == True: exportmap(m, newPDF) else: arcpy.AddMessage('Skipping %s' % newPDF) arcpy.GetMessages() 

The original I used was this, the only reason I modified was to see if I could play around with it and get it to work for me:

''' Export a folder of maps to PDFs at their Map Document set sizes Known to work ArcGIS 10.4.1 and Python 2.7.3 Adapted from work by @bteranUFA and @Guest Batch exporting MXD to PDF files using ArcGIS Desktop? License X/MIT; (c) 2017 Environment Yukon, Matt Wilkie '''

import os import glob import arcpy # Folder to look for MXDs in in_path = arcpy.GetParameterAsText(0) # Where to save output documents exportPath = arcpy.GetParameterAsText(1) if exportPath == '': exportPath = in_path overwrite = arcpy.GetParameter(2) arcpy.AddMessage('Overwrite: %s' % overwrite) # Set the PDF parameters as variables here: data_frame = 'PAGE_LAYOUT' # PAGE_LAYOUT or dataframe name df_export_width = 1920 # ignored when using PAGE_LAYOUT df_export_height = 1200 resolution = '300' image_quality = 'BEST' # FASTEST, FASTER, NORMAL, BETTER, BEST colorspace = 'RGB' # RGB, CMYK compress_vectors = 'True' image_compression = 'ADAPTIVE' # ADAPTIVE, JPEG, DEFLATE, LZW, RLE, NONE picture_symbol = 'VECTORIZE_BITMAP' # RASTERIZE_BITMAP, RASTERIZE_PICTURE, VECTORIZE_BITMAP convert_markers = 'False' embed_fonts = 'True' layers_attributes = 'LAYERS_ONLY' # LAYERS_ONLY, LAYERS_AND_ATTRIBUTES, NONE georef_info = 'True' jpeg_compression_quality = 85 maps = glob.glob(os.path.join(in_path, '*.mxd')) def exportmap(mxdPath, exportPath): fname = os.path.split(mxdPath)[1] # ''some_map.mxd' - discard prefix path elements basename = os.path.splitext(fname)[0] # 'some_map' - discard extension newPDF = os.path.join(exportPath, basename + '.pdf') # 'Y:\output\some_map.pdf' open(newPDF, 'w').close() # create empty marker file , for parallel script running. arcpy.AddMessage('Reading: ' + m) mxd = arcpy.mapping.MapDocument(m) arcpy.AddMessage('Writing: ' + newPDF) arcpy.mapping.ExportToPDF(mxd, newPDF, data_frame, df_export_width, df_export_height, resolution, image_quality, colorspace, compress_vectors, image_compression, picture_symbol, convert_markers, embed_fonts, layers_attributes, georef_info, jpeg_compression_quality) del mxd return for m in maps: fname = os.path.split(m)[1] # ''some_map.mxd' - discard prefix path elements basename = os.path.splitext(fname)[0] # 'some_map' - discard extension newPDF = os.path.join(exportPath, basename + '.pdf') # 'Y:\output\some_map.pdf' arcpy.AddMessage('--- %s' % os.path.split(m)[1]) if os.path.exists(newPDF): if overwrite == True: exportmap(m, newPDF) else: arcpy.AddMessage('Skipping %s' % newPDF) arcpy.GetMessages() 

After copying and pasting those scripts and looking at how the preview of my question looks I am sure I did not paste them in properly (I am seriously not savvy with scripts and coding at all and quite literally need my hand held, sorry).

I am hoping there is perhaps an updated toolbox/script that will allow me to export an entire folder of mxds into individual pdfs?

I did try to use the Export MXD to PDF (Python Script & Toolbox Tool) from Esri as well but did not have any luck with it either. It asks for a folder but when you go to choose a folder it actually wants you to choose a single file which is not what I want to do. I do not have the knowledge to run it as a "batch script in toolbox" as Esri suggests in the link.

I am running ArcMap 10.7 and have a Basic license.

0

1 Answer 1

1

My suggestion would be to:

  1. Create a python list of mxds. Copy/paste each mxd full path into the list. ArcCatalog is good for this.

enter image description here

  1. Export maps as described in the esri technical support.

Example:

import arcpy, os #list of mxds mxd_list = [r"C:\Users\e1b8\Desktop\E1B8\Example\Example.mxd", r"C:\Users\e1b8\Desktop\E1B8\Example\Example2.mxd", r"C:\Users\e1b8\Desktop\E1B8\Example\Example3.mxd"] #iterate list for mxd in mxd_list: #map documoent object current_mxd = arcpy.mapping.MapDocument (mxd) #out PDF name pdf_name = mxd[:-4] + ".pdf" #export map arcpy.mapping.ExportToPDF(current_mxd, pdf_name) print os.path.basename (pdf_name) 
1
  • I came across a suggestion on a different post (after I posted my question) that it may be due to the file names having special characters? My file names have numbers, letters, dashes, and underscores. I might give your suggestion a try if we can't figure this out. The problem is I typically have anywhere from 20 to around 100 individual mxds to pdf so the folder option really is ideal if it is possible. Thank you! Commented May 28, 2019 at 23:03

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.