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.
I am not very savvy with this kind of stuff.
I'm sure this paragraph will get deleted and that's ok, but I wanted to apologize for not editing my original question. I hadn't received any email notifications letting me know there were questions/comments for me as well as a notification to elaborate and provide more detail. I finally had some free time today to get back to trying to solve this problem so I thought I'd check my question, hence the huge time gap between my original post and now. I also didn't realize my question would get deleted after a certain amount of time of not hearing from me (probably missed that tidbit somewhere along the line). I'll see if I can find in my account where to set up email notifications (assuming that there is a way). Thank you for your time and assistance!