granth

Python and Data Driven Pages

Discussion created by granth on May 5, 2011
Latest reply on May 9, 2011 by granth
I am having real trouble exporting to PDF - dataDrivenPages.exportToPDF()

I can export fine if I use the defaults (just passing through a reference to the out_pdf) but as soon as I start adding parameters it fails, whether I try and pass them through or type them.



mxdMain = arcpy.mapping.MapDocument(r"C:\Main.mxd")
pdfMainOutput1 = r"C:\ResMapMain1.pdf"
pageCount = mxdMain.dataDrivenPages.pageCount
pageStart = pageCount - 1
outputToEnd = '"' + str(pageStart) + '-' + str(pageCount) + '"'

pdfMain = mxdMain.dataDrivenPages.exportToPDF(pdfMainOutput1, page_range_type="RANGE", page_range_string=outputToEnd, multiple_files="PDF_SINGLE_FILE", resolution=200, layers_attributes="NONE", georef_info="FALSE")



results in:

Traceback (most recent call last):
File "C:\Projects\TestDDP_params.py", line 36, in <module>
pdfMain = mxdMain.dataDrivenPages.exportToPDF(pdfMainOutput1, page_range_type="RANGE", page_range_string=outputToEnd, multiple_files="PDF_SINGLE_FILE", resolution=200, layers_attributes="NONE", georef_info="FALSE")
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_
return fn(*args, **kw)
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 400, 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), True)))
AttributeError: PageLayoutObject: Error in exporting pages

I thought it mght have been the passing of the outputToEnd reference in the page_range parameter, but it still fails with the same error when I tried the following:


pdfMain = mxdMain.dataDrivenPages.exportToPDF(pdfMainOutput1, page_range_type="RANGE", page_range_string="79-80", multiple_files="PDF_SINGLE_FILE", resolution=200, layers_attributes="NONE", georef_info="FALSE")


I am pretty new to Python so have I made a simple error or is there something with the dataDrivenPages that doesn't like parameters like this? I don't have the same problem with the standard arcpy.mapping.exportToPDF running on a non-data driven pages mxd -

pdfTitle = arcpy.mapping.ExportToPDF(mxdCover, pdfTitle, resolution=200,layers_attributes="NONE", georef_info="FALSE")


works fine

Outcomes