AnsweredAssumed Answered

Runtime error Traceback (most recent call last): File <string>, line 12, in <module> File c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\_mapping.py, line 1013, in appendPages return convertArcObjectToPythonObject(self._arc_object.appendPages(*gp_f

Question asked by kurakuen on Sep 11, 2018
Latest reply on Sep 12, 2018 by Dan_Patterson
I am trying to create an map with embedded title page and extra reports pages. Seems that I need to use Python scripts for this. I am not programmer and never worked with python. I found necessary script but then faced with a problem to make an export of pages from mxd.

Please see the error:

Runtime error Traceback (most recent call last): File <string>, line 12, in <module> File c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\_mapping.py, line 1013, in appendPages return convertArcObjectToPythonObject(self._arc_object.appendPages(*gp_fixargs((pdf_path, password_for_pdf), True))) AttributeError: Invalid path

 

I found a relevant post here

arcmap - ArcPy Data Driven Pages AttributeError: PageLayoutObject: Error in exporting pages - Geographic Information Sys… 

and modified the script but got an error again:

 

import arcpy, os

 

# Create an output location variable

outDir = "C:/temp/MBExample/temp_pdfs/Final" 

 

# Create a new, empty pdf document in the specified output location folder

finalpdf_filename = outDir + "/Test_Atlas_Final.pdf"

if os.path.exists(finalpdf_filename):

  os.remove(finalpdf_filename)

finalPdf = arcpy.mapping.PDFDocumentCreate(finalpdf_filename)

 

# Add the title page to the pdf

finalPdf.appendPages("C:/temp/MBExample/temp_pdfs/TitlePage.pdf")

 

# Add the overview map to the pdf

finalPdf.appendPages("C:/temp/MBExample/temp_pdfs/IndexMap.pdf")

 

# Export the Data Driven Pages to a temporary pdf and then add it to the

# final pdf. Alternately, if your Data Driven Pages have already been

# exported, simply append that document to the final pdf.

#

mxdPath = " S:/7352-Asset Services Apps/GIS/PROJECTS/Local Intake Areas Boundary Capture/Working/PrimarySchools/2018_Metro_Regions_Grid.mxd "

tempMap = arcpy.mapping.MapDocument(mxdPath)

tempDDP = tempMap.dataDrivenPages

temp_filename = "C:/temp/MBExample/temp_pdfs/tempDDP"

if os.path.exists(temp_filename):

  os.remove(temp_filename)

tempDDP.exportToPDF(temp_filename, "ALL")

finalPdf.appendPages(temp_filename + ".pdf")

 

# Insert the pdf pages containing the reports and graphs into the final pdf

#

finalPdf.insertPages("C:/temp/MBExample/temp_pdfs/Report_pg1.pdf", 1)

# Update the properties of the final pdf

finalPdf.updateDocProperties(pdf_open_view="USE_THUMBS",

pdf_layout="SINGLE_PAGE")


# Save your result
finalPdf.saveAndClose() # Delete variablesdel finalPdf

Outcomes