Multiple Map Series into PDF

1279
5
11-01-2021 02:56 AM
FynnScharpen
Occasional Contributor

Good Morning,

I'm searching for a way to export multiple map series into pdfs.

Detailed Description:

I have 4 different layouts, each being a map series, and I'm trying to write a script that appends:

Layout 1 Page 1 + Layout  2  Page 1 +  Layout  3  Page 1 +  Layout  4  Page 1 into one pdf...

that should loop based on the number of pages in the map series (each map series has the same amount).

(for example: 50 pdfs with 4 pages each)

 

I'm not a python pro so I would be grateful for any suggestions. 

 

Thanks in advance Fynn

Tags (3)
5 Replies
jcarlson
MVP Esteemed Contributor

I know the Esri folks have talked about a forthcoming Map Book tool that might be able to do something like this, if I recall. For the time being, however, you'd have to do it yourself using the arcpy.mp submodule in Python. Which, as you mention, is not the ideal solution for you.

Just to elaborate on that anyway, though, since it's the most direct solution without leaving ArcGIS Pro, you would have something like this:

import arcpy
import os

aprx = arcpy.mp.ArcGISProject('path/to/your/project.aprx')

lyt1 = aprx.listLayouts('name-of-first-layout')[0]
lyt2 = aprx.listLayouts('name-of-second-layout')[0]
lyt3 = aprx.listLayouts('name-of-third-layout')[0]
lyt4 = aprx.listLayouts('name-of-fourth-layout')[0]

# Access your features, either through a cursor or something.
# Depends on your situation, maybe, but I use the ArcGIS Python API, as I am working with web layers and find it easier.

for f in features:
    # Create a PDF with feature-based name
    pdfDoc = arcpy.mp.PDFDocumentCreate('path/to/PDF.pdf')

    # Adjust your layouts' extent, text, etc
    # Again, depends entirely on your particular layout

    # Export layouts to temp files
    lyt1.exportToPDF('temp_1.pdf')
    lyt2.exportToPDF('temp_2.pdf')
    lyt3.exportToPDF('temp_3.pdf')
    lyt4.exportToPDF('temp_4.pdf')

    # Append temp files to main PDF doc
    pdfDoc.appendPages('temp_1.pdf')
    pdfDoc.appendPages('temp_2.pdf')
    pdfDoc.appendPages('temp_3.pdf')
    pdfDoc.appendPages('temp_4.pdf')

    # Save and close PDF doc
    pdfDoc.saveAndClose()
    del pdfDoc

    # Remove temp files
    os.remove('temp_1.pdf')
    os.remove('temp_2.pdf')
    os.remove('temp_3.pdf')
    os.remove('temp_4.pdf')

There's a lot more to it than that, but it may already be more than you want to deal with if you're not into Python solutions.

Alternative: Secondary Software

An alternate approach to this problem is to use additional software. There exist a number of options to address this very situation, ranging from free and open-source to paid options, but the simple fact is that if you don't want to get into the Python, you'll need to merge your PDFs using something other than Pro.

 

Finally, I'd point you to this Idea I posted that would allow for a single "layout" to consist of multiple pages. If it were implemented, your problem would be solved! Just put all 4 pages together in one layout! It's a trivial matter in software like QGIS, but still lacking in Pro. Give it a vote!

- Josh Carlson
Kendall County GIS
FynnScharpen
Occasional Contributor

First of all thank you jcarlson! I just started with arcpy so this will help a lot. I used Adobe Acrobat DC before the problem is since im having multiple map series i have to do the merg 100+ times. The only thing thats mising is how i gonna loop your script to repeat it over and over again. Thanks anyway Fynn

0 Kudos
jcarlson
MVP Esteemed Contributor

No problem!

To loop over things, you'll just need to use a search cursor in arcpy, or iterate over a list of features generated via the ArcGIS Python API.

- Josh Carlson
Kendall County GIS
0 Kudos
JeffreyBarrette
New Contributor

The above script is great but may look a little 'long' for someone new to Python.  The sample below is directly from the PDFDocument class in the arcpy.mp help:

https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/pdfdocument-class.htm

The following lines of code are the minimum needed to append 3 PDFs (multi-page or not) into a single multi-page PDF.  The example above does the extra work of cleaning up the individual PDFs.

import arcpy

pdfDoc = arcpy.mp.PDFDocumentCreate(pdfPath)

pdfDoc.appendPages(r"C:\Projects\YosemiteNP\Title.pdf")

pdfDoc.appendPages(r"C:\Projects\YosemiteNP\MapPages.pdf")

pdfDoc.appendPages(r"C:\Projects\YosemiteNP\ContactInfo.pdf")

pdfDoc.saveAndClose()

 

Jeff - arcpy.mp and Layout teams

jcarlson
MVP Esteemed Contributor

The tricky part is getting this to work as a map series, instead of doing it manually for each feature in a layer. Can't wait for that Map Book!

- Josh Carlson
Kendall County GIS