Select to view content in your preferred language

My "ExportToPDF" Python scripts no longer work

1380
2
10-02-2018 03:15 PM
ScottMcGee4
Regular Contributor

I have some Python scripts that export MXDs to PDFs. I initially created the scripts when we were using ArcGIS 10.5.x and they worked just fine - no errors.

We recently upgraded to 10.6.1 and now the scripts blow up with the following errors:

Traceback (most recent call last):
  File "T:\Export-pdf-KY-1-of-1.py", line 45, in <module>
    jpeg_compression_quality=vExportJpgCompression)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\utils.py", line 182, in fn_
    return fn(*args, **kw)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\mapping.py", line 1156, in ExportToPDF
    layout.exportToPDF(*args)
AttributeError: PageLayoutObject: Error in executing ExportToPDF

I've triple-checked to make sure there are no syntax errors, misspellings, or other errors in my scripts. Like I said, they used to work perfectly in 10.5.x, but not now in 10.6.1. I looked at the code in the Python scripts that are mentioned in the error message above, but I have no idea what to look for to try to fix the issue with my ExportToPDF scripts.

Any ideas?

Tags (1)
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

There are bugs, like

NIM062177: ExportToPDF using arcpy does not export a layer attr.. 

but none specifically targeted to 10.6

Perhaps the code might reveal something

0 Kudos
AdamDaily
Frequent Contributor

Same issue here exporting a series of mxds to pdf containing data driven pages. I had a script that worked great in 10.5. Now on 10.6 they dont work at all. Interestingly, if I copy the same script over to our ArcGIS server (also with 10.6 and Python 2.7.14) and run through task manager, everything works again. On Desktop I get 8 pages of the first mxd map series exported out as my temp.pdf before the crash. Script/Traceback error below if anyone has any ideas:

Script Running from IDLE using Python 2.7.14 MSC v.1500 32 bit (Intel)] on win32

import sys, arcpy, os, string

mxdlist = ['Map1','Map2', 'Map3']

for m in mxdlist:
### Create Empty PDF file that will hold individual maps
finalPdf = arcpy.mapping.PDFDocumentCreate(r"C:\\folder\\" + m + ".pdf")

### Define location of the mxd
mxd = arcpy.mapping.MapDocument(r"C:\\Folder\\" + m + ".mxd")

tmpPdf = r"C:\\Folder\\Temp.pdf"
ddp = mxd.dataDrivenPages
ddp.exportToPDF(tmpPdf, "ALL")
finalPdf.appendPages(tmpPdf)

del mxd, tmpPdf, finalPdf

os.remove("C:\\Folder\\Temp.pdf")

Returns:

Traceback error: (most recent call last):

File "location\Script.py", line 15, in <module>
ddp.exportToPDF(tmpPdf, "ALL")
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\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

0 Kudos