<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python Code for Map Series PDF export with multiple layouts in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407684#M81635</link>
    <description>&lt;P&gt;Quick answer, you can use either the&amp;nbsp;&lt;STRONG&gt;os&lt;/STRONG&gt; or&amp;nbsp;&lt;STRONG&gt;pathlib&lt;/STRONG&gt; module:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;os.remove(temp_pdf)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;General consensus is that &lt;STRONG&gt;pathlib&lt;/STRONG&gt; is designed around path-like objects and is the better library to use for stuff like this.&amp;nbsp; The code below assumes temp_pdf is a Path() object, instead of a regular string like you have in your code.&amp;nbsp; My longer reply below is built around &lt;STRONG&gt;pathlib&lt;/STRONG&gt;, if you want to see the difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;temp_pdf.unlink()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think &lt;STRONG&gt;pathlib&lt;/STRONG&gt; is unavailable to Python 2, though, which means no &lt;STRONG&gt;pathlib&lt;/STRONG&gt; in ArcGIS Desktop, if you're still using it.&amp;nbsp; Though, if you are: You should definitely consider upgrading to Pro, anyway.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, for a more comprehensive answer comparing the two, I'm just going to link to this StackOverflow page: &lt;A href="https://stackoverflow.com/questions/6996603/how-can-i-delete-a-file-or-folder-in-python" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/6996603/how-can-i-delete-a-file-or-folder-in-python&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Apr 2024 19:15:32 GMT</pubDate>
    <dc:creator>MErikReedAugusta</dc:creator>
    <dc:date>2024-04-09T19:15:32Z</dc:date>
    <item>
      <title>Python Code for Map Series PDF export with multiple layouts</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407564#M81615</link>
      <description>&lt;P&gt;Hi everyone!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to preface this by saying I am VERY new to coding so I could be doing this totally wrong. Also, please let me know if I'm posting this question in the wrong board.&lt;/P&gt;&lt;P&gt;In ArcGIS Pro, I wanted to be able to export a single PDF file consisting of Spatial Map Series Pages. However, I needed it to export two different layouts, alternating between layouts. For example, it would look like: FirstLayout Page 1, SecondLayout Page 1,&amp;nbsp;FirstLayout Page 2, SecondLayout Page 2, FirstLayout Page 3, SecondLayout 3.... and so on.&lt;/P&gt;&lt;P&gt;The code I wrote works, but I have a few questions because I want to simplify it and somehow create a tool out of it so I don't have to input the code every time.&lt;/P&gt;&lt;P&gt;Here's the code with questions:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# coding: utf-8
# This code groups FirstLayout with SecondLayout and exports in one PDF file.

#FIRST QUESTION: do all of these need to be imported for this specific task? Does it even matter? I am still confused about the whole third-party module concept.

import arcpy
import os
import sys 

# Set the output PDF file path
output_pdf = r'C:\Users\BlahBlah\FilePath\Code Testing\Test.pdf'

#SECOND QUESTION: Is there a way to have the code auto fill layout names? 
Currently, I have to replace layout names every time I change it.

# List of layout names
layout_names = ['FirstLayout', 'SecondLayout']

# Reference the active ArcGIS Pro Project
aprx = arcpy.mp.ArcGISProject("CURRENT")

# Create the PDF document
pdf_document = arcpy.mp.PDFDocumentCreate(output_pdf)

#THIRD QUESTION: Here is where I get messed up. I should be able to reference the map series below, under "# Iterate through the unique IDs" BUT if I don't reference the map series before that step, I get this error message:
"&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\_base.py", line 90, in _get
    return convertArcObjectToPythonObject(getattr(self._arc_object, attr_name))
RuntimeError: Unexpected error."-- Why?? 

#Reference the map series
for layout_name in layout_names:
        layout = aprx.listLayouts(layout_name)[0]
        map_series = layout.mapSeries

# Iterate through the unique IDs
for unique_id in range(1, map_series.pageCount + 1):
    for layout_name in layout_names:
        layout = aprx.listLayouts(layout_name)[0]
        map_series = layout.mapSeries
        map_series.currentPageNumber = unique_id
        pageName = map_series.pageRow.UNI_IDS__LO_  # UniqueID is the attribute field name used to define the map series. Change accordingly if a different field name is used.
        temp_pdf = r'C:\Users\BlahBlah\FilePath\Code Testing\TempLayout.pdf'
        layout.exportToPDF(temp_pdf)
        pdf_document.appendPages(temp_pdf)

#LAST QUESTION: Does this always have to be loaded after the code is done?

# After the software finishes the PDF, enter this.
pdf_document.saveAndClose()
&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 09 Apr 2024 15:20:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407564#M81615</guid>
      <dc:creator>Amp_Dev</dc:creator>
      <dc:date>2024-04-09T15:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python Code for Map Series PDF export with multiple layouts</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407571#M81617</link>
      <description>&lt;P&gt;Totally forgot! I also want to auto delete the templayout.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 15:27:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407571#M81617</guid>
      <dc:creator>Amp_Dev</dc:creator>
      <dc:date>2024-04-09T15:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Python Code for Map Series PDF export with multiple layouts</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407573#M81618</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;Hope it's okay to tag you guys! I've looked at a lot of your posts and you two seem to be pretty knowledgeable so I wonder if either of you have any feedback! Please and thank you in advanced!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 15:31:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407573#M81618</guid>
      <dc:creator>Amp_Dev</dc:creator>
      <dc:date>2024-04-09T15:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Python Code for Map Series PDF export with multiple layouts</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407603#M81620</link>
      <description>&lt;P&gt;Oof. It's been a minute since I worked with layouts through ArcPy. Creating a complex map series, or anything with multiple pages in it, can be an absolute pain in the neck.&lt;/P&gt;&lt;P&gt;Personally? I just use QGIS for those kinds of things. I still don't really know the arcpy.mp module well enough to give you good guidance here, other than just avoid it unless you absolutely have to use it.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 16:19:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407603#M81620</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-04-09T16:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Python Code for Map Series PDF export with multiple layouts</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407623#M81626</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Line 4/Question 1:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The simple answer is, "If you didn't use it in your code, then it doesn't need to be up here."&amp;nbsp; I highly recommend grabbing an IDE like PyCharm or Spyder (&lt;U&gt;&lt;STRONG&gt;not&lt;/STRONG&gt;&lt;/U&gt; IDLE), if you haven't already.&amp;nbsp; They often have tools that will help you keep track of whether or not a library is actually in use by that code, and some will even insert the import statement for you if you call something you haven't imported, yet.&amp;nbsp; I prefer PyCharm, but that's a highly subjective determination.&lt;/P&gt;&lt;P&gt;I'll come back to Questions 2-4 in a bit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First, let's look at the general structure of your script:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;OL&gt;&lt;LI&gt;import some stuff&lt;/LI&gt;&lt;LI&gt;Create a list of 2 items: "&lt;STRONG&gt;layout_names&lt;/STRONG&gt;"&lt;/LI&gt;&lt;LI&gt;access the currently-open APRX file&lt;/LI&gt;&lt;LI&gt;create a blank PDF file&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Line 25/Question 3:&lt;/STRONG&gt; The reason you have to do this first is that PDFDocumentCreate appears to treat the PDF as essentially a list of pages.&amp;nbsp; You can't append things to a list that doesn't exist, so you have to create an empty document, first, and then you can append pages to it.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Loop through &lt;STRONG&gt;layout_names&lt;/STRONG&gt;.&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Line 13/Question 2:&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;I'm actually going to address this one here.&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;aprx.listLayouts(layout_name)&lt;/STRONG&gt; will return a list of all Layouts that match the search string you put inside the parentheses.&amp;nbsp; It's an optional argument, too.&lt;/LI&gt;&lt;LI&gt;Instead, you could theoretically just look for all layouts.&amp;nbsp; If the only layout files in your APRX are FirstLayout and SecondLayout, then it'll automatically pull them, regardless of name.&lt;/LI&gt;&lt;LI&gt;The tricky part is going to be if you have more layouts and/or if your naming conventions sort the way you want to.&lt;UL&gt;&lt;LI&gt;Having layout files "Option1" and "Layout2" would actually make "Layout2" the FirstLayout, since it comes alphabetically first, for example.&lt;/LI&gt;&lt;LI&gt;Having layout files "Layout1", "Layout2", "Layout3" would produce "Layout1-Page1, Layout2-Page1, Layout3-Page1, Layout1-Page2, [...]".&amp;nbsp; It's up to you whether or not this is desirable.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Lines 31-33 are almost entirely redundant of Lines 38-40.&amp;nbsp; They're going to be overwritten by the later lines and can be completely ignored &amp;amp; removed.&lt;/LI&gt;&lt;LI&gt;The only thing this&amp;nbsp;&lt;EM&gt;functionally&lt;/EM&gt; does is give you an iterable object that you can use in Line 37 to tell you how many pages to expect, but it's&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;always&lt;/STRONG&gt;&lt;/EM&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;going to be the Map Series for "SecondLayout", since the last iteration of this loop overwrites all previous ones.&lt;/LI&gt;&lt;LI&gt;It's worth noting that if SecondLayout has fewer pages than FirstLayout, you'll be missing the last pages of FirstLayout, because SecondLayout is entirely driving the bus on the loop.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Loop through each expected page and for each layout in layout_names (in that order), do the following:&lt;UL&gt;&lt;LI&gt;List all layouts that match the search string from layout_names, and take the first result as "layout"&lt;/LI&gt;&lt;LI&gt;Read the map series in&amp;nbsp;&lt;STRONG&gt;layout&lt;/STRONG&gt;, and retrieve the current expected page number&lt;/LI&gt;&lt;LI&gt;Save that page as a single-page temporary PDF&lt;/LI&gt;&lt;LI&gt;Append that temporary PDF page to your PDF document that you created up in Step 4&lt;/LI&gt;&lt;LI&gt;Repeat&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;There appears to be a lot of redundancy &amp;amp; inefficiency in this script, to me.&amp;nbsp; For one, that last loop: For&amp;nbsp;&lt;EM&gt;every page of SecondLayout&lt;/EM&gt;, you pull the whole map series, navigate to the matching page, and do some stuff.&amp;nbsp; I don't know what the memory hit is for pulling the whole map series, but this sort of process in general is unideal.&lt;/P&gt;&lt;P&gt;First, here's the rough structure for how I would do this.&amp;nbsp; I'm going to include actual Python code below, but if you want to try to dissect &amp;amp; understand this, see if you can write it, first, and then compare against how I did it.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;OL&gt;&lt;LI&gt;Access the current APRX file&lt;/LI&gt;&lt;LI&gt;Pull a list of all Layout Files in that APRX and save it to&amp;nbsp;&lt;STRONG&gt;layer_files&lt;/STRONG&gt;.&lt;UL&gt;&lt;LI&gt;Make sure you're saving the actual layer objects you get back from&amp;nbsp;&lt;STRONG&gt;.listLayouts()&lt;/STRONG&gt;—it'll save you from having to pull them up again later&lt;/LI&gt;&lt;LI&gt;If there's a consistent search string in the name that you can look for, it's worth putting it into the command.&amp;nbsp; Otherwise, just pull them all and cross your fingers that you named them in a sortable way.&lt;/LI&gt;&lt;LI&gt;If this doesn't "just work", then you'll always need to provide the Layout Names, whether as a hardcoded parameter like this, or as an Input to a Tool.&amp;nbsp; Either way,&amp;nbsp;&lt;STRONG&gt;layer_files&lt;/STRONG&gt; should always have layer objects inside it.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Create your blank PDF file for later&lt;/LI&gt;&lt;LI&gt;Create a &lt;STRONG&gt;master_page_count&lt;/STRONG&gt; variable and set it to 0&lt;/LI&gt;&lt;LI&gt;Compare the page counts of all Layout Files from Step 2 against&amp;nbsp;&lt;STRONG&gt;master_page_count&lt;/STRONG&gt;, and save the highest page count you find to that variable&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;P&gt;&amp;nbsp;Quick Notes:&lt;BR /&gt;&lt;STRONG&gt;Line 1&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-SPOILER&gt;If you're pasting it into the Python Window in ArcGIS, then you don't actually need to put "import arcpy".&amp;nbsp; I usually still do, though, when I'm writing it outside in my IDE, so that my IDE can actually see it.&amp;nbsp; If you're creating a Script Tool in ArcGIS, I genuinely can't remember if you need arcpy or not; I think you do.&amp;nbsp; I always include it either way, again because of the IDE, and because it's generally good practice to manually include whatever you're calling, anyway.&lt;/LI-SPOILER&gt; &lt;STRONG&gt;Line 2&lt;BR /&gt;&lt;/STRONG&gt;&lt;LI-SPOILER&gt;&lt;STRONG&gt;pathlib&lt;/STRONG&gt; is a library designed specifically for working with paths.&amp;nbsp; Explaining it is a bit beyond the scope of this post, but I'm trying to switch myself over to using this, instead of the old ways of doing things with&amp;nbsp;&lt;STRONG&gt;os&lt;/STRONG&gt;, &lt;STRONG&gt;glob&lt;/STRONG&gt;, and the like.&lt;/LI-SPOILER&gt; &lt;STRONG&gt;Line 9&lt;BR /&gt;&lt;/STRONG&gt;&lt;LI-SPOILER&gt;I'm just going to call my final PDF "ResultPDF.pdf" for simplicity's sake.&amp;nbsp; There are a bunch of options for how you can handle this, here.&amp;nbsp; For my workflows, it's usually simplest just to provide&amp;nbsp;&lt;EM&gt;where&lt;/EM&gt; I want it to save, let the tool name the file(s), and then rename things as-needed when it's all done.&lt;BR /&gt;&lt;BR /&gt;Also, I've gone ahead and taken the string that the tool input gave me and converted it to a Path object to save me a step down the line.&lt;/LI-SPOILER&gt; &lt;STRONG&gt;Lines 14–27&lt;/STRONG&gt;&lt;BR /&gt;&lt;LI-SPOILER&gt;The goal here is to create one master list of Layout objects.&amp;nbsp; First, are all layouts that match searchString1.&amp;nbsp; Then, all layouts that match searchString2.&amp;nbsp; If something somehow matches both search strings, then it only gets added once.&lt;BR /&gt;&lt;BR /&gt;Lines 23–78 are a failsafe.&amp;nbsp; If we haven't found any Layout objects by this point, then we have a problem; nothing matched.&amp;nbsp; If the user provided search strings (Line 24), then there were no matches; let them know with an Error message.&amp;nbsp; If the user&amp;nbsp;&lt;EM&gt;didn't&amp;nbsp;&lt;/EM&gt;provide search strings, then just export&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;every single Layout file in the project.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/LI-SPOILER&gt; &lt;STRONG&gt;Lines 35–36&lt;BR /&gt;&lt;/STRONG&gt;&lt;LI-SPOILER&gt;Explaining the pathlib module is beyond the scope of this post, as stated above.&amp;nbsp; The short version here: I create a Path object that points to a file called "Final_Output.pdf" in the directory provided in &lt;STRONG&gt;Line 9&lt;/STRONG&gt;.&lt;/LI-SPOILER&gt;&lt;P&gt;&lt;STRONG&gt;Line 45&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-SPOILER&gt;This&amp;nbsp;&lt;EM&gt;should&lt;/EM&gt; be the correct syntax to delete the temporary PDF file.&amp;nbsp; Full disclosure: I'm still getting a feel for &lt;STRONG&gt;pathlib&lt;/STRONG&gt; and switching my code over to using it.&lt;/LI-SPOILER&gt; &lt;LI-CODE lang="python"&gt;import arcpy
import pathlib

### TOOL IMPORTS ############################################################
#   If you're not making this a tool, replace arcpy.GetParameterAsText(#)
#   with the actual hardcoded value.
searchString1 = arcpy.GetParameterAsText(0)
searchString2 = arcpy.GetParameterAsText(1)
pdf_folder    = pathlib.Path(arcpy.GetParameterAsText(3))


### LAYOUT FILES, PAGE COUNT ################################################
aprx = arcpy.mp.ArcGISProject('CURRENT')
layout_files = []
if searchString1 != '':
  for layout in aprx.listLayouts(searchString1):
    if layout not in layout_files:
      layout_files.append(layout)
if searchString2 != '':
  for layout in aprx.listLayouts(searchString2):
    if layout not in layout_files:
      layout_files.append(layout)
if len(layout_files) &amp;lt;= 0:
  if searchString1 != '' or searchString2 != '':
    raise ValueError('Provided search strings returned no results.  Unable to export files')
  else:
    layout_files = aprx.listLayouts()

expected_page_count = 0
for layout in layout_files:
  if layout.mapSeries.pageCount + 1 &amp;gt; expected_page_count:
    expected_page_count = layout.mapSeries.pageCount + 1

### PREPARE PDF #############################################################
pdfDoc = pdf_folder / 'Final_Output.pdf'
pdfDoc = arcpy.mp.PDFDocumentCreate(pdfDoc)

### EXPORT! #################################################################
for pageNumber in range(1, expected_page_count):
  for layout in layout_files:
    layout.currentPageNumber = pageNumber
    tempPDF = pdf_folder / 'TEMP.pdf'
    layout.exportToPDF(tempPDF)
    pdfDoc.appendPages(tempPDF)
    tempPDF.unlink()
pdfDoc.saveAndClose()&lt;/LI-CODE&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 19:14:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407623#M81626</guid>
      <dc:creator>MErikReedAugusta</dc:creator>
      <dc:date>2024-04-09T19:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: Python Code for Map Series PDF export with multiple layouts</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407684#M81635</link>
      <description>&lt;P&gt;Quick answer, you can use either the&amp;nbsp;&lt;STRONG&gt;os&lt;/STRONG&gt; or&amp;nbsp;&lt;STRONG&gt;pathlib&lt;/STRONG&gt; module:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;os.remove(temp_pdf)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;General consensus is that &lt;STRONG&gt;pathlib&lt;/STRONG&gt; is designed around path-like objects and is the better library to use for stuff like this.&amp;nbsp; The code below assumes temp_pdf is a Path() object, instead of a regular string like you have in your code.&amp;nbsp; My longer reply below is built around &lt;STRONG&gt;pathlib&lt;/STRONG&gt;, if you want to see the difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;temp_pdf.unlink()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think &lt;STRONG&gt;pathlib&lt;/STRONG&gt; is unavailable to Python 2, though, which means no &lt;STRONG&gt;pathlib&lt;/STRONG&gt; in ArcGIS Desktop, if you're still using it.&amp;nbsp; Though, if you are: You should definitely consider upgrading to Pro, anyway.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, for a more comprehensive answer comparing the two, I'm just going to link to this StackOverflow page: &lt;A href="https://stackoverflow.com/questions/6996603/how-can-i-delete-a-file-or-folder-in-python" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/6996603/how-can-i-delete-a-file-or-folder-in-python&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 19:15:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-code-for-map-series-pdf-export-with/m-p/1407684#M81635</guid>
      <dc:creator>MErikReedAugusta</dc:creator>
      <dc:date>2024-04-09T19:15:32Z</dc:date>
    </item>
  </channel>
</rss>

