As a test I have:

  1. Authored a test.mxd with one layer called Localities in a single data frame called Layers
  2. Authored a test.rlf using View | Reports > Create Report of ArcGIS 10.2.2 for Desktop
  3. Created a Python AddIn which creates the expected PDF file from the Report (*.rlf).

This is the code which all works to create the PDF report from the Localities features within the current extent:

import arcpy 
import pythonaddins

class ReportForExtent(object):
    def __init__(self):
        self.enabled = True
        self.checked = False

    def onClick(self):
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
        lyr = arcpy.mapping.ListLayers(mxd,"Localities",df)[0]
        del mxd

Is there a way to have the Python AddIn not just create the PDF file but also open it in Adobe Acrobat Reader?


You could use

import os
myfile = r"C:\temp\test.pdf"
os.system("start " + myfile)

Just tested running this chunk of code from Python add-in from ArcMap and it works fine. More discussion on using this is here.

Alternatively, as commented by @JasonScheirer you could use os.startfile which works even if the pathname has a space in it, and the asker says does exactly what they were hoping.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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