Résumé
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.
Discussion
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.
Propriétés
Propriété | Explication | Type de données |
definitionQuery (Lecture et écriture) | The reports's definition query. This is applied in addition to the report's reference data source definition query. | String |
metadata (Lecture et écriture) | Get or set the report's Metadata class information. Note, setting metadata is dependent on the isReadOnly property value. | Metadata |
name (Lecture et écriture) | 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 (Lecture seule) | Returns the report's reference data source connection information as a Python dictionary. | Dictionary |
Vue d’ensemble des méthodes
Méthode | Explication |
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. |
Méthodes
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})
Paramètre | Explication | Type de données |
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.
(La valeur par défaut est 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. (La valeur par défaut est 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. (La valeur par défaut est None) | Integer |
resolution | An integer that defines the resolution of the export file in dots per inch (dpi). (La valeur par défaut est 96) | Integer |
image_quality | A string that defines output image quality.
(La valeur par défaut est BEST) | String |
compress_vector_graphics | A Boolean that controls compression of vector and text portions of the output file. Image compression is defined separately. (La valeur par défaut est True) | Boolean |
image_compression | A string that defines the compression scheme used to compress image or raster data in the output file.
(La valeur par défaut est 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. (La valeur par défaut est 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. (La valeur par défaut est 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.
Exemple de code
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")
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()
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()
Vous avez un commentaire à formuler concernant cette rubrique ?