Is it possible in a map series to customize each PDF export with a dynamic title in the PDF Metadata under the Accessibility tab?
Solved! Go to Solution.
As of ArcGIS Pro 3.5.3 it is not possible to update the PDF metadata for each page in the Accessibility tab. There may be some scripting options available with arcpy.mp, although I'm not 100% sure about that.
As of ArcGIS Pro 3.5.3 it is not possible to update the PDF metadata for each page in the Accessibility tab. There may be some scripting options available with arcpy.mp, although I'm not 100% sure about that.
If you can't do it during the export operation, you could always just change the PDF Metadata after the fact using pypdf. You'll need to customize this for your desired title string, but the concept worked when I tested it.
from pypdf import PdfWriter, PdfReader
import os
# get project and layout vars
p = arcpy.mp.ArcGISProject("CURRENT")
layout_name = "Name of the layout with the map series"
l = p.listLayouts(layout_name)[0]
#directory to save the output pdfs
folder_path = r"where to save these pdfs"
if not l.mapSeries is None: #if the layout contains a MapSeries
ms = l.mapSeries #define the mapSeries object
if ms.enabled:
ms = l.mapSeries
for pageNum in range(1, ms.pageCount + 1): #Loop through pages
# update mapseries and Export to PDF
ms.currentPageNumber = pageNum
pdf_file = os.path.join(folder_path,ms.pageRow.FIELDNAME1+'.pdf')
l.exportToPDF(pdf_file)
# Build you desired title string from the fieldnames
title_string = "Metadata for map {}: {}".format(ms.pageRow.FIELDNAME1,ms.pageRow.FIELDNAME2)
reader = PdfReader(pdf_file)
writer = PdfWriter(clone_from=reader)
writer.add_metadata({"/Title": title_string})
with open(pdf_file, "wb") as f:
writer.write(f)