1

I am trying to create an atlas 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 my script:

        import arcpy, os

# Create an output location variable
outDir = "K:/IM/02_GIS/01_Projects/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("K:/IM/02_GIS/01_Projects/TitlePage.pdf")

# Add the overview map to the pdf
finalPdf.appendPages("K:/IM/02_GIS/01_Projects/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 = "K:/IM/02_GIS/01_Projects/AOR_General_v2_Atlas_Test1_1.mxd"
tempMap = arcpy.mapping.MapDocument(mxdPath)
tempDDP = tempMap.dataDrivenPages
temp_filename = "K:/IM/02_GIS/01_Projects/tempDDP.pdf"
if os.path.exists(temp_filename):
  os.remove(temp_filename)
tempDDP.exportToPDF(temp_filename, "ALL")
finalPdf.appendPages(temp_filename)

# Insert the pdf pages containing the reports and graphs into the final pdf
#
finalPdf.insertPages("K:/IM/02_GIS/01_Projects/Report_pg4.pdf", 4)
# Update the properties of the final pdf
finalPdf.updateDocProperties(pdf_open_view="USE_THUMBS",
pdf_layout="SINGLE_PAGE")

# Save your result
finalPdf.saveAndClose()

# Delete variables
del finalPdf

Error I keep getting

Runtime error 
Traceback (most recent call last):
  File "<string>", line 28, in <module>
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\utils.py", line 182, in fn_
    return fn(*args, **kw)
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\utils.py", line 182, in fn_
    return fn(*args, **kw)
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\_mapping.py", line 447, in exportToPDF
    return convertArcObjectToPythonObject(self._arc_object.exportToPDF(*gp_fixargs((out_pdf, page_range_type, page_range_string, multiple_files, resolution, image_quality, colorspace, compress_vectors, image_compression, picture_symbol, convert_markers, embed_fonts, layers_attributes, georef_info, jpeg_compression_quality, show_selection_symbology), True)))
AttributeError: PageLayoutObject: Error in exporting pages

It works well till this step # Add the overview map to the pdf
It adding overview map perfectly and error occurs during proceeding of the next step.

6
  • Based on the error the problem is actually occurring at tempDDP.exportToPDF(temp_filename, "ALL") ; I have had problems here before, one fix was to remove .pdf from the output name as exportToPDF adds the file extension. So I would change temp_filename = "K:/IM/02_GIS/01_Projects/tempDDP.pdf" -to- temp_filename = "K:/IM/02_GIS/01_Projects/tempDDP" then finalPdf.appendPages(temp_filename + ".pdf") Commented Feb 17, 2017 at 14:00
  • @Clubdebambos That would be worth adding as an answer, which would allow you to format the code better also. I recommend including all of that specific code block for clarity ( from mxdPath to finalPdf.appendPages(temp_filename) )
    – Midavalo
    Commented Feb 17, 2017 at 16:34
  • @Midavalo I just ran the code provided by just changing paths and pdfs that I have and everything worked fine. So I don't think my suggestion is the root cause. Commented Feb 17, 2017 at 16:45
  • @Clubdebambos I did also, but if you've had problems there in the past, it is a potential fix. Might be ArcMap version specific
    – Midavalo
    Commented Feb 17, 2017 at 16:46
  • @Dia What ArcGIS version are you running?
    – Midavalo
    Commented Feb 17, 2017 at 16:46

1 Answer 1

1

Change the temp_filename and finalPdf.appendPages(temp_filename + ".pdf")

import arcpy, os

# Create an output location variable
outDir = "K:/IM/02_GIS/01_Projects/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("K:/IM/02_GIS/01_Projects/TitlePage.pdf")

# Add the overview map to the pdf
finalPdf.appendPages("K:/IM/02_GIS/01_Projects/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 = "K:/IM/02_GIS/01_Projects/AOR_General_v2_Atlas_Test1_1.mxd"
tempMap = arcpy.mapping.MapDocument(mxdPath)
tempDDP = tempMap.dataDrivenPages
temp_filename = "K:/IM/02_GIS/01_Projects/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("K:/IM/02_GIS/01_Projects/Report_pg4.pdf", 4)
# Update the properties of the final pdf
finalPdf.updateDocProperties(pdf_open_view="USE_THUMBS",
pdf_layout="SINGLE_PAGE")

# Save your result
finalPdf.saveAndClose()

# Delete variables
del finalPdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.