Report

Zusammenfassung

The Report object references a report in an ArcGIS Pro project (.aprx) file. It provides access to common properties such as definition query and export.

Diskussion

An ArcGIS Pro project can contain multiple reports. Reports are accessed using the listReports method on the ArcGISProject object, and it returns a Python list of Report objects. It is important to uniquely name each report so that a specific report can be easily referenced by its name.

A Report has a data source that provides the data to power the report generation. You can identify the current data source for the report using the referenceDataSource property. To change the report's data source, you can use the setReferenceDataSource method. The method maps the fields from the new data source to the fields of the report that were defined by the original data source. The field names, not the field aliases, must be an exact, case-sensitive match.

In addition to the report's data source having a definition query, the report can also have a definition query. Records are first filtered based on the data source's definition query, and the records can be further filtered using the report's definitionQuery property.

Use the exportToPDF method to export the report to a PDF document.

Eigenschaften

EigenschaftErläuterungDatentyp
definitionQuery
(Lesen und schreiben)

The reports's definition query. This is applied in addition to the report's reference data source definition query.

String
metadata
(Lesen und schreiben)

Get or set the report's Metadata class information. Note, setting metadata is dependent on the isReadOnly property value.

Metadata
name
(Lesen und schreiben)

The report's name. It is important that all reports in a project have a unique name so they can be easily referenced by name.

String
referenceDataSource
(Schreibgeschützt)

Returns the report's reference data source connection information as a Python dictionary.

Dictionary

Methodenübersicht

MethodeErläuterung
exportToPDF (out_pdf, {page_range_type}, {page_range}, {starting_page_number}, {total_page_number}, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {jpeg_compression_quality})

Exports a report to a Portable Document Format (PDF) file.

setReferenceDataSource (data_source)

Sets a report's reference data source.

Methoden

exportToPDF (out_pdf, {page_range_type}, {page_range}, {starting_page_number}, {total_page_number}, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {jpeg_compression_quality})
ParameterErläuterungDatentyp
out_pdf

A string that represents the path and file name of the output export file.

String
page_range_type

A string that defines the type of page range to export. The default is ALL.

  • ALLExport all pages of the report.
  • LASTExport the last page of the report.
  • EVENExport the even numbered pages of the report.
  • ODDExport the odd numbered pages of the report.
  • RANGEExport the pages listed in the page_range parameter .

(Der Standardwert ist ALL)

String
page_range

A string that identifies the pages to be exported if the RANGE option in the page_range_type parameter is used (for example, 1, 3, 5-12). If any other page_range_type value is used, the page_range value will be ignored.

String
starting_page_number

Applies an offset to the page numbering to add additional pages to the beginning of the report. The default offset is 1.

(Der Standardwert ist 1)

Integer
total_page_number

The total number of pages to label, for example, when your report displays X of Y pages. This is useful when you want to combine multiple reports into one. The default is -1, which means there is no override.

(Der Standardwert ist None)

Integer
resolution

An integer that defines the resolution of the export file in dots per inch (dpi).

(Der Standardwert ist 96)

Integer
image_quality

A string that defines output image quality.

  • BESTAn output image quality resample ratio of 1
  • BETTERAn output image quality resample ratio of 2
  • NORMALAn output image quality resample ratio of 3
  • FASTERAn output image quality resample ratio of 4
  • FASTESTAn output image quality resample ratio of 5

(Der Standardwert ist BEST)

String
compress_vector_graphics

A Boolean that controls compression of vector and text portions of the output file. Image compression is defined separately.

(Der Standardwert ist True)

Boolean
image_compression

A string that defines the compression scheme used to compress image or raster data in the output file.

  • ADAPTIVEAutomatically selects the best compression type for each image on the page. JPEG will be used for large images with many unique colors. DEFLATE will be used for all other images.
  • JPEGA lossy data compression.
  • DEFLATEA lossless data compression
  • LZWLempel-Ziv-Welch, a lossless data compression
  • NONECompression is not applied
  • RLERun-length encoded compression

(Der Standardwert ist ADAPTIVE)

String
embed_fonts

A Boolean that controls the embedding of fonts in an 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.

(Der Standardwert ist 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 through 100. A jpeg_compression_quality of 100 provides the best quality images but creates large export files. The recommended range is 70 through 90.

(Der Standardwert ist 80)

Integer

PDF files are designed to be consistently viewable and printable across platforms. They are commonly used for distributing documents on the web and are a standard interchange format for content delivery. PDF files are editable in many graphics applications and retain annotation, labeling, and attribute data for map layers. PDF exports support embedding of fonts and can display symbology correctly even if the user does not have Esri fonts installed.

setReferenceDataSource (data_source)
ParameterErläuterungDatentyp
data_source

The data reference that powers the report. This parameter can be a Layer object, a Table object, or a string that represents the path to an external data source.

(Der Standardwert ist None)

Object

The setReferenceDataSource method sets the data source that the report references using a Layer object, a Table object, or a string that represents the path to an external data source

Codebeispiel

Report example 1

The following script selects the Counties Report by name and exports it to PDF.

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\USA_States\USA_States.aprx")
report = aprx.listReports("Counties Report")[0]
report.exportToPDF(r"C:\Project\USA_States\CA_Counties_Report.pdf")
Report example 2

The following script repairs the report's broken data source and saves the project.

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\USA_States\USA_States.aprx")
report = aprx.listReports("Counties Report")[0] # has a broken data source
report.setReferenceDataSource(r"C:\Project\USA_States\usa.gdb\states")
print(report.referenceDataSource)
#{'dataset':'states', 'workspace_factory':'File Geodatabase',
# 'connection_info':{'database':'C:\\Project\\USA_States\\usa.gdb'}}
aprx.save()
Report example 3

The following script uses the PDFDocument class to merge multiple reports into one multipage PDF.

import arcpy
pdf_name = "StatesReport.pdf"
cover_page = r"C:\path\to\StatesCoverPage.pdf"
part_one_pdf = r"C:\path\to\part_one.pdf"
part_two_pdf = r"C:\path\to\part_two.pdf"
final_pdf_path = r"C:\path\to\StatesReport.pdf"
report1 = self.aprx.listReports("States Report")[0] # Attribute List template
report2 = self.aprx.listReports("States Report Summaries")[0] # Summaries only using Basic Summary template
report1.exportToPDF(part_one_pdf, starting_page_number=2, total_page_number=13, page_range_type="RANGE",
                    page_range="1-2")
report2.exportToPDF(part_two_pdf, starting_page_number=3, total_page_number=13, page_range_type="RANGE",
                    page_range="2-11")

pdfMerge = arcpy.mp.PDFDocumentCreate(final_pdf_path) # Creates an empty PDF
pdfMerge.appendPages(cover_page)
pdfMerge.appendPages(part_one_pdf)
pdfMerge.appendPages(part_two_pdf)
pdfMerge.saveAndClose()