Skip to main content
Tweeted twitter.com/StackGIS/status/1115902389511512065
Format the code, fixed a couple of typos, edit sentences lightly for clarity
Source Link

I am a novice Python user but I am trying to create a script which will allow me to export all of the data driven pages within an mxd to a single pdf file (without having to open the mxd). I currently have thisthe script (attached)below which works for exporting single pages; andpages. And the highlighted section was my intialinitial (poor) attempt to export all pages based on what I have seen or read.

# Python script to run in windows.

1) Copy script into folder to run script

2) Edit quality and dpi variables if desired

import arcpy, os

get current directory python script is in

cwd = os.getcwd()

quality to export, BEST, BETTER, NORMAL, FASTER, FASTEST

quality = "BEST"

dots per inch resolution

dpi = "300" res = int(dpi)

Ask user to confirm settings and directory

print "Export ArcMap MXD(s) to PDF(s), " + quality + " Quality, " + dpi + "dpi to " + cwd + "?"

pauses for user to press key to continue

os.system('pause')

set folder path to current directory

folderPath = cwd

prints message to console for user

print "IN PROGRESS...PLEASE WAIT..."

counter to count number of PDFs

n = 0

create fullpath from filename and folder path

for filename in os.listdir(folderPath):
fullpath = os.path.join(folderPath, filename)

extract file extension

# 1) Copy script into folder to run script
# 2) Edit quality and dpi variables if desired

import arcpy, os

# get current directory python script is in
cwd = os.getcwd()

# quality to export, BEST, BETTER, NORMAL, FASTER, FASTEST 
quality = "BEST"
# dots per inch resolution
dpi = "300"
res = int(dpi)

# Ask user to confirm settings and directory
print "Export ArcMap MXD(s) to PDF(s), " + quality + " Quality, " + dpi + "dpi to " + cwd + "?"

# pauses for user to press key to continue
os.system('pause')

# set folder path to current directory
folderPath = cwd

# prints message to console for user
print "IN PROGRESS...PLEASE WAIT..."

# counter to count number of PDFs
n = 0

# create fullpath from filename and folder path
for filename in os.listdir(folderPath):  
    fullpath = os.path.join(folderPath, filename)
# extract file extension
    if os.path.isfile(fullpath):  
        basename, extension = os.path.splitext(fullpath)  
        if extension.lower() == ".mxd":

advance counter to count PDFs

# advance counter to count PDFs
            n = n + 1
            mxd = arcpy.mapping.MapDocument(fullpath)

export tool with parameters

# export tool with parameters
            arcpy.mapping.ExportToPDF(mxd, basename + '.pdf', resolution=res, image_quality=quality, colorspace="RGB", picture_symbol="VECTORIZE_BITMAP", layers_attributes="NONE")
            print basename + "...exported"
            
            del mxd 

# prints message to console for user
nstr = str(n)
print nstr + " pdf(s) exported to " + folderPath
print "DONE"

# pauses for user to press key to continue
os.system('pause')

prints message to console for user

nstr = str(n) print nstr + " pdf(s) exported to " + folderPath print "DONE"

pauses for user to press key to continue

os.system('pause')

I am a novice Python user but I am trying to create a script which will allow me to export all of the data driven pages within an mxd to a single pdf file (without having to open the mxd) I currently have this script (attached) which works for exporting single pages; and the highlighted section was my intial (poor) attempt to export all pages based on what I have seen or read.

# Python script to run in windows.

1) Copy script into folder to run script

2) Edit quality and dpi variables if desired

import arcpy, os

get current directory python script is in

cwd = os.getcwd()

quality to export, BEST, BETTER, NORMAL, FASTER, FASTEST

quality = "BEST"

dots per inch resolution

dpi = "300" res = int(dpi)

Ask user to confirm settings and directory

print "Export ArcMap MXD(s) to PDF(s), " + quality + " Quality, " + dpi + "dpi to " + cwd + "?"

pauses for user to press key to continue

os.system('pause')

set folder path to current directory

folderPath = cwd

prints message to console for user

print "IN PROGRESS...PLEASE WAIT..."

counter to count number of PDFs

n = 0

create fullpath from filename and folder path

for filename in os.listdir(folderPath):
fullpath = os.path.join(folderPath, filename)

extract file extension

if os.path.isfile(fullpath):  
    basename, extension = os.path.splitext(fullpath)  
    if extension.lower() == ".mxd":

advance counter to count PDFs

        n = n + 1
        mxd = arcpy.mapping.MapDocument(fullpath)

export tool with parameters

        arcpy.mapping.ExportToPDF(mxd, basename + '.pdf', resolution=res, image_quality=quality, colorspace="RGB", picture_symbol="VECTORIZE_BITMAP", layers_attributes="NONE")
        print basename + "...exported"
        
        del mxd

prints message to console for user

nstr = str(n) print nstr + " pdf(s) exported to " + folderPath print "DONE"

pauses for user to press key to continue

os.system('pause')

I am a novice Python user but I am trying to create a script which will allow me to export all of the data driven pages within an mxd to a single pdf file (without having to open the mxd). I currently have the script below which works for exporting single pages. And the highlighted section was my initial (poor) attempt to export all pages based on what I have seen or read.

# Python script to run in windows.
# 1) Copy script into folder to run script
# 2) Edit quality and dpi variables if desired

import arcpy, os

# get current directory python script is in
cwd = os.getcwd()

# quality to export, BEST, BETTER, NORMAL, FASTER, FASTEST 
quality = "BEST"
# dots per inch resolution
dpi = "300"
res = int(dpi)

# Ask user to confirm settings and directory
print "Export ArcMap MXD(s) to PDF(s), " + quality + " Quality, " + dpi + "dpi to " + cwd + "?"

# pauses for user to press key to continue
os.system('pause')

# set folder path to current directory
folderPath = cwd

# prints message to console for user
print "IN PROGRESS...PLEASE WAIT..."

# counter to count number of PDFs
n = 0

# create fullpath from filename and folder path
for filename in os.listdir(folderPath):  
    fullpath = os.path.join(folderPath, filename)
# extract file extension
    if os.path.isfile(fullpath):  
        basename, extension = os.path.splitext(fullpath)  
        if extension.lower() == ".mxd":
# advance counter to count PDFs
            n = n + 1
            mxd = arcpy.mapping.MapDocument(fullpath)
# export tool with parameters
            arcpy.mapping.ExportToPDF(mxd, basename + '.pdf', resolution=res, image_quality=quality, colorspace="RGB", picture_symbol="VECTORIZE_BITMAP", layers_attributes="NONE")
            print basename + "...exported"
            
            del mxd 

# prints message to console for user
nstr = str(n)
print nstr + " pdf(s) exported to " + folderPath
print "DONE"

# pauses for user to press key to continue
os.system('pause')
added 1560 characters in body
Source Link

I am a novice Python user but I am trying to create a script which will allow me to export all of the data driven pages within an mxd to a single pdf file (without having to open the mxd) I currently have this script (attached) which works for exporting single pages; and the highlighted section was my intial (poor) attempt to export all pages based on what I have seen or read.

# Python script to run in windows.

1) Copy script into folder to run script

2) Edit quality and dpi variables if desired

enter image description here import arcpy, os

get current directory python script is in

cwd = os.getcwd()

quality to export, BEST, BETTER, NORMAL, FASTER, FASTEST

quality = "BEST"

dots per inch resolution

dpi = "300" res = int(dpi)

Ask user to confirm settings and directory

print "Export ArcMap MXD(s) to PDF(s), " + quality + " Quality, " + dpi + "dpi to " + cwd + "?"

pauses for user to press key to continue

os.system('pause')

set folder path to current directory

folderPath = cwd

prints message to console for user

print "IN PROGRESS...PLEASE WAIT..."

counter to count number of PDFs

n = 0

create fullpath from filename and folder path

for filename in os.listdir(folderPath):
fullpath = os.path.join(folderPath, filename)

extract file extension

if os.path.isfile(fullpath):  
    basename, extension = os.path.splitext(fullpath)  
    if extension.lower() == ".mxd":

advance counter to count PDFs

        n = n + 1
        mxd = arcpy.mapping.MapDocument(fullpath)

export tool with parameters

        arcpy.mapping.ExportToPDF(mxd, basename + '.pdf', resolution=res, image_quality=quality, colorspace="RGB", picture_symbol="VECTORIZE_BITMAP", layers_attributes="NONE")
        print basename + "...exported"
        
        del mxd

prints message to console for user

nstr = str(n) print nstr + " pdf(s) exported to " + folderPath print "DONE"

pauses for user to press key to continue

os.system('pause')

I am a novice Python user but I am trying to create a script which will allow me to export all of the data driven pages within an mxd to a single pdf file (without having to open the mxd) I currently have this script (attached) which works for exporting single pages; and the highlighted section was my intial (poor) attempt to export all pages based on what I have seen or read.

enter image description here

I am a novice Python user but I am trying to create a script which will allow me to export all of the data driven pages within an mxd to a single pdf file (without having to open the mxd) I currently have this script (attached) which works for exporting single pages; and the highlighted section was my intial (poor) attempt to export all pages based on what I have seen or read.

# Python script to run in windows.

1) Copy script into folder to run script

2) Edit quality and dpi variables if desired

import arcpy, os

get current directory python script is in

cwd = os.getcwd()

quality to export, BEST, BETTER, NORMAL, FASTER, FASTEST

quality = "BEST"

dots per inch resolution

dpi = "300" res = int(dpi)

Ask user to confirm settings and directory

print "Export ArcMap MXD(s) to PDF(s), " + quality + " Quality, " + dpi + "dpi to " + cwd + "?"

pauses for user to press key to continue

os.system('pause')

set folder path to current directory

folderPath = cwd

prints message to console for user

print "IN PROGRESS...PLEASE WAIT..."

counter to count number of PDFs

n = 0

create fullpath from filename and folder path

for filename in os.listdir(folderPath):
fullpath = os.path.join(folderPath, filename)

extract file extension

if os.path.isfile(fullpath):  
    basename, extension = os.path.splitext(fullpath)  
    if extension.lower() == ".mxd":

advance counter to count PDFs

        n = n + 1
        mxd = arcpy.mapping.MapDocument(fullpath)

export tool with parameters

        arcpy.mapping.ExportToPDF(mxd, basename + '.pdf', resolution=res, image_quality=quality, colorspace="RGB", picture_symbol="VECTORIZE_BITMAP", layers_attributes="NONE")
        print basename + "...exported"
        
        del mxd

prints message to console for user

nstr = str(n) print nstr + " pdf(s) exported to " + folderPath print "DONE"

pauses for user to press key to continue

os.system('pause')

deleted 47 characters in body; edited tags
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I am a novice Python user but I am trying to create a script which will allow me to export all of the data driven pages within an mxd to a single pdf file (without having to open the mxd) I currently have this script (attached) which works for exporting single pages; and the highlighted section was my intial (poor) attempt to export all pages based on what I have seen or read. Any help would be greatly appreciated.

Cheers enter image description here

I am a novice Python user but I am trying to create a script which will allow me to export all of the data driven pages within an mxd to a single pdf file (without having to open the mxd) I currently have this script (attached) which works for exporting single pages; and the highlighted section was my intial (poor) attempt to export all pages based on what I have seen or read. Any help would be greatly appreciated.

Cheers enter image description here

I am a novice Python user but I am trying to create a script which will allow me to export all of the data driven pages within an mxd to a single pdf file (without having to open the mxd) I currently have this script (attached) which works for exporting single pages; and the highlighted section was my intial (poor) attempt to export all pages based on what I have seen or read.

enter image description here

Source Link
Loading