Print and Export Maps from ArcMap with ArcPy Mapping

by | Nov 1, 2010

Printing and exporting maps is obviously one of the most commonly performed ArcGIS tasks.  The new Arcpy.mapping module provides several functions that you can use to automate your routine print and export tasks.  In this post we’ll examine Arcpy.mapping functions you can use for printing and exporting either maps from either the data or layout view in ArcMap.

Arcpy.mapping provides a PrintMap() function for printing page layouts or data frames within ArcMap and a host of Export functions that export the page layout or a data frame to various image formats and PDF files.  Before calling PrintMap() it is common practice to call the ListPrinterNames() function which returns a list of the available printers for the local computer.  A particular printer can then be found by iterating the list of printers and used as input to the PrintMap() function.

PrintMap() can print either a specific data frame or the page layout of a map document.  By default this function will use the printer saved with the map document or, if not present in the map document, the default system printer.  As I mentioned you can also use ListPrinterNames() to get a list of the available printers and select one of these printers as input to PrintMap().  In the code example on below PrintMap() uses the default printer as specified through the use of double quotes as the second parameter to PrintMap().

You can use one of the many Export functions provided by Arcpy.mapping to export a data frame or page layout to an image file.  Available formats include AI, BMP, EMF, EPS, GIF, JPEG, SVG, and TIFF.  The parameters provided for each function will vary depending upon the type of image.  Examples of these function names include ExportToJPEG, ExportToGIF, ExportToBMP, and all the others you see listed here.

You can also export your data frames or page layout to PDF format with ExportToPDF().  PDF is obviously a very popular interchange format so you will likely need to become familiar with this function.  Calling ExportToPDF() is much the same as calling any of the image export functions since it takes an mxd and path to output the file along with optional properties for the PDF.

In addition to exporting your maps to PDF you can also manipulate existing PDF documents or create new PDF documents.  You can merge pages, set document open behavior, add file attachments, and create or change document security settings.  The PDFDocumentOpen() function is used to open an existing PDF file for manipulation.  PDFDocumentCreate() creates a new PDF document.  These functions are often used in the creation of map books.

You’ll need to use PDFDocumentCreate to create a new PDF document by providing a path and filename for the document.  The PDF is not actually created on disk until you insert or append pages and then call PDFDocument.saveAndClose().  The appendPages() and insertPages() functions are used to insert and append pages.

PDFDocumentOpen accepts a parameter that specifies the path to a PDF file and returns an instance of PDFDocument.  Once open you can make modifications to PDF file properties, add or insert files, and attach documents.  Make sure you call PDFDocument.saveAndClose() after all operations to save the changes to disk.

A number of properties can be set on a PDF Document through the PDFDocument object including getting a page count, attaching files, updating title, author, subject, keywords, open behavior, and the layout.  You can also update the document security by calling PDFDocument.updateDocSecurity() to set a password, encryption, and security restrictions.

Categories

Recent Posts

Eric Pimpler
Eric is the founder and owner of GeoSpatial Training Services (geospatialtraining.com) and has over 25 years of experience implementing and teaching GIS solutions using ESRI, Google Earth/Maps, Open Source technology. Currently Eric focuses on ArcGIS scripting with Python, and the development of custom ArcGIS Server web and mobile applications using JavaScript. Eric is the author of Programming ArcGIS with Python Cookbook - 1st and 2nd Edition, Building Web and Mobile ArcGIS Server Applications with JavaScript, Spatial Analytics with ArcGIS, and ArcGIS Blueprints. Eric has a Bachelor’s degree in Geography from Texas A&M University and a Master's of Applied Geography degree with a concentration in GIS from Texas State University.

Sign up for our weekly newsletter
to receive content like this in your email box.