[bug] mapSeries.exportToPDF - no suffix for single page range

155
1
07-25-2024 03:59 PM
TaylorCarnell1
Occasional Contributor

When exporting a map series with mapSeries.exportToPDF, if the page_range_string is a single page with page_range_type="RANGE" and multiple_files=["PDF_MULTIPLE_FILES_PAGE_NUMBER" | "PDF_MULTIPLE_FILES_PAGE_NAME"], a suffix is not added.

e.g.

map_series.exportToPDF("path/to/test.pdf", page_range_type="RANGE",page_range_string="1", multiple_files="PDF_MULTIPLE_FILES_PAGE_NUMBER")
# "path/to/test.pdf"

map_series.exportToPDF("path/to/test.pdf", page_range_type="RANGE",page_range_string="1,2", multiple_files="PDF_MULTIPLE_FILES_PAGE_NUMBER")
# "path/to/test_1.pdf"
# "path/to/test_2.pdf"
 
I can see this being considered expected behaviour, but it is problematic when batching multiple exports for dynamic ranges and inconsistent with the documentation:
 
  • PDF_MULTIPLE_FILES_PAGE_NUMBERExport each map series page to an individual file and append the page number to the file name. For example, Output.PDF will become Output_1.PDF

The simplest workaround, that I currently employ, is to specify the page twice, when the range is 1.

1 Reply
TonyAlmeida
Frequent Contributor

Here is something I use,

 

 

import arcpy

def export_map_series(map_series, output_path, custom_range_type, page_range_string, custom_multiple_files_option):
    # Check if the page_range_string is a single page
    if custom_range_type == "CUSTOM_RANGE" and custom_multiple_files_option in ["CUSTOM_PAGE_NUMBER", "CUSTOM_PAGE_NAME"]:
        pages = page_range_string.split(",")
        if len(pages) == 1:
            # Duplicate the page number if it's a single page
            page_range_string = f"{pages[0]},{pages[0]}"
    
    # Map custom names to ArcGIS Pro export options
    range_type_mapping = {
        "CUSTOM_RANGE": "RANGE"
    }
    
    multiple_files_mapping = {
        "CUSTOM_PAGE_NUMBER": "PDF_MULTIPLE_PAGE_NUMBER",
        "CUSTOM_PAGE_NAME": "PDF_MULTIPLE_PAGE_NAME"
    }
    
    # Perform the export
    map_series.exportToPDF(output_path, 
                           page_range_type=range_type_mapping[custom_range_type], 
                           page_range_string=page_range_string, 
                           multiple_files=multiple_files_mapping[custom_multiple_files_option])

# Example usage
project = arcpy.mp.ArcGISProject("CURRENT")
layout = project.listLayouts()[0]  # Assuming the first layout is the one you want to use
map_series = layout.mapSeries
output_path = r"C:\Temp\CaseMaps.pdf"
custom_range_type = "CUSTOM_RANGE"
page_range_string = "1"  # Change this to test with a single page
custom_multiple_files_option = "CUSTOM_PAGE_NUMBER"

export_map_series(map_series, output_path, custom_range_type, page_range_string, custom_multiple_files_option)

 

 

 

0 Kudos