Python code to export mxd to pdf with date value on the pdf



 

# Name: Exporttopdf.py
# Date: February 11, 2015
# Author: SGurung
# Description: This code creates pdf map from mxd file. The pdf file can have date value attached on # its name, e.g., "testmap_date.pdf". The code can be scheduled on task scheduler to run it at your
# desired time.
# ---------------------------------------------------------------------------

# import arcpy module
import arcpy

# import datetime module. Date value can be today, yesterday or as defined by user
import datetime
today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)

# Overwrite output file if it already exist
arcpy.OverWriteOutput =True

# Define the location of mxd
mxd = arcpy.mapping.MapDocument(r"C:\input\test.mxd")

# Define the output location and then date value as needed to be displayed on the pdf file
# %d = day of the month, %b = abbreviated month name, %y = year
pdf = r"C:\output\Maps\\" + "testmap_" + yesterday.strftime('%d%b%Y') + ".pdf"

# Set pdf parameters as per your requirement here:
data_frame = 'PAGE_LAYOUT'
resolution = "300"
image_quality = "NORMAL"
colorspace = "RGB"
compress_vectors = "True"
image_compression = "DEFLATE"
picture_symbol = 'RASTERIZE_BITMAP'
convert_markers = "False"
embed_fonts = "True"
layers_attributes = "NONE"
georef_info = "False"

# Export mxd to pdf
arcpy.mapping.ExportToPDF(mxd, pdf, data_frame, 640, 480, resolution, image_quality, colorspace, compress_vectors, image_compression, picture_symbol, convert_markers, embed_fonts, layers_attributes, georef_info)

# Release mxd
del mxd

Post a Comment