Summary
The Layout object references a single-page layout in an ArcGIS Pro project (.aprx). It provides access to common properties like page size and a number of different export methods.
Discussion
An ArcGIS Pro project can contain multiple page layouts. Layouts are accessed using the listLayouts method on the ArcGISProject object and it returns a Python list of Layout objects. It is important to uniquely name each layout so a specific page layout can be easily referenced by its name.
The listLayouts method provides access to all the elements on the page layout: GraphicElement, LegendElement, MapFrameElement, MapSurroundElement, PictureElement, and TextElement.
The Layout object is where you'll find access to a number of exportTo methods. Use the Layout export methods if you want to export the entire page layout. There is also a similar set of export methods available on the MapFrame class, if you only want to export the contents of a single map frame.
A layout can contain a single MapSeries. If the mapSeries property returns None, then a map series has not been created in the layout. You should also check to see if the map series is enabled before attempting to manipulate its properties.
Properties
Property | Explanation | Data Type |
mapSeries (Read and Write) | If the layout has a map series defined, it returns the MapSeries object. Confirm that the map series is enabled with the enabled property. | MapSeries |
name (Read and Write) | The layout's name. It is important that all layouts have a unique name so they can be easily referenced by name. | String |
pageHeight (Read and Write) | A layout's page height based on the current pageUnits. | Double |
pageUnits (Read and Write) | A layout's page units. Below is a list of valid strings when setting the page units.
| String |
pageWidth (Read and Write) | A layout's page width based on the current pageUnits. | Double |
Method Overview
Method | Explanation |
exportToBMP (out_bmp, {resolution}) | Exports the page layout to the Microsoft Windows Bitmap format (BMP). |
exportToEMF (out_emf, {resolution}) | Exports the page layout to the Enhanced Metafile (EMF) format. |
exportToEPS (out_eps, {resolution}) | Exports the page layout to an Encapsulated PostScript (EPS) format. |
exportToGIF (out_gif, {resolution}) | Exports the page layout to the Graphic Interchange format (GIF). |
exportToJPEG (out_jpg, {resolution}, {jpeg_color_mode}, {jpeg_quality}) | Exports the page layout to a Joint Photographic Experts Group (JPEG) format file. |
exportToPDF (out_pdf, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality}, {clip_to_elements}) | Exports the page layout to the Portable Document Format (PDF). |
exportToPNG (out_png, {resolution}, {color_mode}) | Exports the page layout to a Portable Network Graphics (PNG) format file. |
exportToSVG (out_svg, {resolution}, {compress_to_svgz}) | Exports the page layout to the Scalable Vector Graphics format (SVG). |
exportToTGA (out_tga, {resolution}) | Exports the page layout to the Truevision Graphics Adapter format (TGA). |
exportToTIFF (out_tif, {resolution}, {color_mode}, {tiff_compression}) | Exports the page layout to a Tagged Image File Format (TIFF) file. |
listElements ({element_type}, {wildcard}) | Returns a Python list of page layout elements that exist on a Layout object. |
Methods
exportToBMP (out_bmp, {resolution})
Parameter | Explanation | Data Type |
out_bmp | A string that represents the path and file name for the output export file. | String |
resolution | A number that defines the resolution of the export file in dots per inch (dpi). (The default value is 96) | Integer |
BMP files are native Windows raster images. BMPs can store pixel data at several bit depths. BMP images are typically much larger than formats such as JPEG or PNG.
exportToEMF (out_emf, {resolution})
Parameter | Explanation | Data Type |
out_emf | A string that represents the system path and file name for the output export file. | String |
resolution | A number that defines the resolution of the export file in dots per inch (dpi). (The default value is 96) | Integer |
EMF files are native Windows graphics files that can contain a mixture of vector and raster data. They are useful for embedding in Windows documents because the vector portions of the EMF can be resized without loss of quality. However, since EMF does not support font embedding and is exclusively a Windows format, it is not commonly used as an interchange format between users.
exportToEPS (out_eps, {resolution})
Parameter | Explanation | Data Type |
out_eps | A string that represents the system path and file name for the output export file. | String |
resolution | A number that defines the resolution of the export file in dots per inch (dpi). (The default value is 96) | Integer |
EPS files use the PostScript page description language to describe vector and raster objects. PostScript is the publishing industry standard for high-end graphics files, cartography, and printing. EPS files can be edited in many drawing applications or placed as a graphic in most page layout applications. EPS files support embedding of fonts so users who do not have Esri fonts installed can still view the proper symbology.
exportToGIF (out_gif, {resolution})
Parameter | Explanation | Data Type |
out_gif | A string that represents the system path and file name for the output export file. | String |
resolution | A number that defines the resolution of the export file in dots per inch (dpi). (The default value is 96) | Integer |
GIF files are a legacy raster format for use on the web. GIFs cannot contain more than 256 colors (8-bits per pixel), which along with optional lossless compression, makes them smaller than other file formats.
exportToJPEG (out_jpg, {resolution}, {jpeg_color_mode}, {jpeg_quality})
Parameter | Explanation | Data Type |
out_jpg | A string that represents the path and file name of the output export file. | String |
resolution | A number that defines the resolution of the export file in dots per inch (dpi). (The default value is 96) | Integer |
jpeg_color_mode | This value specifies the number of bits used to describe color.
(The default value is 24-BIT_TRUE_COLOR) | String |
jpeg_quality | This value (0–100) controls the amount of compression applied to the output image. With a JPEG image, quality is adversely affected the more compression is applied. A higher quality (highest = 100) setting will produce sharper images and larger file sizes. A lower quality setting will produce more image artifacts and smaller files. (The default value is 80) | Integer |
JPEG files are compressed image files. They support 24-bit color and are a popular choice for use on the web because a JPEG file size is often substantially smaller than many other image formats. However, the JPEG compression algorithm is lossy and is not recommended for many map images, as line drawings, and text or icon graphics, become blurred by compression artifacts. Therefore, PNG is usually a superior format for map images.
exportToPDF (out_pdf, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality}, {clip_to_elements})
Parameter | Explanation | Data Type |
out_pdf | A string that represents the path and file name for the output export file. | String |
resolution | A number that defines the resolution of the export file in dots per inch (DPI). (The default value is 300) | Integer |
image_quality | A string that defines output image quality, the draw resolution of map layers that draw as rasters.
(The default value is BEST) | String |
compress_vector_graphics | A Boolean that controls compression of vector and text portions of the output file. Image compression is defined separately. (The default value is True) | Boolean |
image_compression | A string that defines the compression scheme used to compress image or raster data in the output file.
(The default value is ADAPTIVE) | String |
embed_fonts | A Boolean that controls the embedding of fonts in the export file. Font embedding allows text and character markers to be displayed correctly when the document is viewed on a computer that does not have the necessary fonts installed. (The default value is True) | Boolean |
layers_attributes | A string that controls inclusion of PDF layer and PDF object data (attributes) in the export file.
(The default value is LAYERS_ONLY) | String |
georef_info | A Boolean that enables the export of coordinate system information for each data frame into the output PDF file. (The default value is True) | Boolean |
jpeg_compression_quality | A number that controls compression quality value when image_compression is set to ADAPTIVE or JPEG. The valid range is 1 to 100. A jpeg_compression_quality of 100 provides the best-quality images but creates large export files. The recommended range is between 70 and 90. (The default value is 80) | Integer |
clip_to_elements | If set to True, the layout is clipped to the smallest bounding box that includes all layout elements. (The default value is False) | Boolean |
PDF files are designed to be consistently viewable and printable across different platforms. They are commonly used for distributing documents on the web, and the format is now an official ISO standard for document interchange. PDFs are editable in many graphics applications and retain map georeference information, annotation, labeling, and feature attribute data. PDF exports support embedding of fonts and thus can display symbology correctly even if the user does not have Esri fonts installed.
Review the PDFDocument class to learn more about how to manage PDF files, such as appending, inserting, and setting properties.
exportToPNG (out_png, {resolution}, {color_mode})
Parameter | Explanation | Data Type |
out_png | A string that represents the path and file name of the output export file. | String |
resolution | A number that defines the resolution of the export file in dots per inch (dpi). (The default value is 96) | Integer |
color_mode | This value specifies the number of bits used to describe color.
(The default value is 24-BIT_TRUE_COLOR) | String |
A PNG file is a versatile raster format file that can display in web browsers and be inserted into other documents. It supports high-bit-depth color and uses a lossless compression. For maps, PNG is often the best raster format, since the lossless compression keeps text and line work legible by preventing the compression artifacts that can occur in JPEG format. PNG files can also define a transparent color.
exportToSVG (out_svg, {resolution}, {compress_to_svgz})
Parameter | Explanation | Data Type |
out_svg | A string that represents the path and file name for the output export file. | String |
resolution | A number that defines the resolution of the export file in dots per inch (dpi). (The default value is 96) | Integer |
compress_to_svgz | If set to True, the output is compressed. (The default value is False) | Boolean |
SVG is an XML-based file format that has been specifically designed for viewing on the web. SVG can contain both vector and raster information. Some web browsers may require a plug-in to view SVG files. Older browsers may not be able to view SVG files at all. SVG supports font embedding, so users who do not have Esri fonts installed can still view SVG exports with proper symbology. You can also choose to produce compressed SVG files. The file extension changes to *.svgz when this option is enabled.
exportToTGA (out_tga, {resolution})
Parameter | Explanation | Data Type |
out_tga | A string that represents the path and file name for the output export file. | String |
resolution | A number that defines the resolution of the export file in dots per inch (dpi). (The default value is 96) | Integer |
TGA files have historically been used for content that is meant to be used in other applications (for example, image sprites for animated games) and is read and written by many popular graphic arts applications.
exportToTIFF (out_tif, {resolution}, {color_mode}, {tiff_compression})
Parameter | Explanation | Data Type |
out_tif | A string that represents the path and file name of the output export file. | String |
resolution | A number that defines the resolution of the export file in dots per inch (dpi). (The default value is 96) | Integer |
color_mode | This value specifies the number of bits used to describe color.
(The default value is 24-BIT_TRUE_COLOR) | String |
tiff_compression | This value represents a compression scheme.
(The default value is LZW) | String |
TIFF files are the best choice for importing into image editing applications and are also a common GIS raster data format. However, they cannot be natively viewed by a web browser.
listElements ({element_type}, {wildcard})
Parameter | Explanation | Data Type |
element_type | A string that represents the element type that will be used to filter the returned list of elements.
(The default value is None) | String |
wildcard | A wildcard is based on the element name and is not case sensitive. A combination of asterisks (*) and characters can be used to help limit the results. (The default value is None) | String |
Data Type | Explanation |
List | A Python list of page layout elements. The types of objects that can be returned are GraphicElement, LegendElement, MapFrame, MapsurroundElement, PictureElement, and TextElement. |
Each page element has a name property that can be set within the element properties dialog box. It is the layout author's responsibility to ensure each page element is given a unique name so that elements can be uniquely identified. If two elements have the same name, there is no way to ensure it is the element you want to reference.
The listElements method will return the elements within a group element into a flattened list. This makes it possible to easily search and replace text strings, for example, without having to navigate through a group element structure.
The element_type parameter can be skipped by passing an empty string or by including the parameter name for all parameters that follow the skipped parameter. For example elm = lyt.listElements("", "Title")[0]
#or
elm = lyt.listElements(wildcard="Title")[0]
Code sample
The following script uses the keyword current, so it should be run from the Python window. The script prints the name of each map in a project and its layers as well as the name of each layout and its page size.
aprx = arcpy.mp.ArcGISProject("CURRENT")
for m in aprx.listMaps():
print("Map: " + m.name)
for lyr in m.listLayers():
print(" " + lyr.name)
print("Layouts:")
for lyt in aprx.listLayouts():
print(" {0} ({1} x {2} {3})".format(lyt.name, lyt.pageHeight, lyt.pageWidth, lyt.pageUnits))
The following script will update a map frame's area of interest by zooming to each bookmark that belongs to a map called Yosemite National Park and exports the result to individual PDF documents.
import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
lyt = aprx.listLayouts("Main Attractions*")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT", "Yosemite National Park*")[0]
bkmks = mf.map.listBookmarks()
for bkmk in bkmks:
mf.zoomToBookmark(bkmk)
lyt.exportToPDF(r"C:\Projects\YosemiteNP" + "\\" + bkmk.name + ".pdf")
del aprx
The following script will check for the presence of a map series, then export two of its pages out to PDF.
import arcpy
import os
import sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(relpath + "\\MapSeries\\US_States.aprx")
l = p.listLayouts()[0]
if not l.mapSeries is None:
ms = l.mapSeries
if ms.enabled:
ms.currentPageNumber = ms.getPageNumberFromName("Rhode Island")
ms.exportToPDF(relpath + "\\Output\\Ex1_RI.pdf", "CURRENT", resolution=300)
ms.currentPageNumber = ms.getPageNumberFromName("Washington")
ms.exportToPDF(relpath + "\\Output\\Ex1_WA.pdf", "CURRENT")