Sending your map layout to a printer is easy with the PrintMap()
function. By default, the print job will be sent to the default printer saved with the map document, but you can also define a specific printer to which the job should be sent.
The arcpy.mapping
module provides a PrintMap()
function to print page layouts or data frames from ArcMap. Before calling PrintMap()
, it is a 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 that can be used as an input for 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, the default system printer in the map document. As I mentioned earlier, you can also use ListPrinterNames()
to get a list of the available printers, and select one of these printers as an input for PrintMap()
. In this recipe, you will learn how to use the PrintMap()
function to print the layout.
Follow these steps to learn how to use the PrintMap()
function to print the layout view in ArcMap:
C:ArcpyBookCh4Crime_Ch4.mxd
in ArcMap.arcpy.mapping
module:import arcpy.mapping as mapping
Crime_Ch4.mxd
), and assign this reference to a variable:mxd = mapping.MapDocument("CURRENT")
Test_Performance
data frame and print it if it's found:for df in mapping.ListDataFrames(mxd): if df.name == "Test_Performance": mapping.PrintMap(mxd,"",df)
c:ArcpyBookcodeCh4PrintingWithPrintMap.py
solution file.The PrintMap()
function accepts one required parameter and a handful of optional parameters. The required parameter is a reference to the map document. The first optional parameter is the printer name. In this case, we haven't specified a particular printer to use. Since we haven't provided a specific printer; it will use the printer saved with the map document or the default system printer if a printer is not part of the map document. The second optional parameter is the data frame that we'd like to print, which in this instance is Test_Performance
. Other optional parameters, not supplied in this case, are an output print file and image quality.