I am using the following script in the python window in ArcMap 10.5.1 desktop to export a layout to a PDF. It works perfectly the first time, but after that then there is no reaction, no error message, nothing. I have tried changing Geoprocessing > Geoprocessing Options so that Overwrite the output of geoprocessing operations is enable but this seems to make no difference.

Why might this be happening?

mxd = arcpy.mapping.MapDocument("CURRENT")
arcpy.mapping.ExportToPDF(mxd, r"C:\Mapsfolder\20191010-0056875154.pdf")
del mxd
  • Try changing the name of your pdf dynamically. – Keshav Sharma Oct 24 '19 at 9:40
  • Seems to work fine in 10.2 and 10.6. Is the old file not being replaced, or is a new file not being created when the first one has been moved elsewhere? – JiyuuSensei Oct 24 '19 at 9:49
  • Have you closed and restarted ArcMap? If ArcMap ever behaves in an odd way I find that a simple restart will often fix it. – PolyGeo Oct 24 '19 at 10:03
  • It seems to work now after a restart of ArcMap, but I have found this to be a reoccuring problem - that it works only once. I am now wondering if it is a problem with the mxd, that it may be corrupted in some way – Malcolm Alexander Oct 24 '19 at 12:26
  • @KeshavSharma Do you have any suggestions for how to do this? – Malcolm Alexander Oct 24 '19 at 12:27

I used the function below in some scripts, and works.

def exportDataDriven(mxdFile, outputPDF, range_index="", range_type = "ALL", multiple_files = "PDF_MULTIPLE_FILES_PAGE_NAME"):
   mxd = arcpy.mapping.MapDocument(mxdFile)
   ddp = mxd.dataDrivenPages
   print "NUMBER OF PAGES: " + str(ddp.pageCount)
   ddp.exportToPDF(outputPDF, range_type, resolution = 300, page_range_string=range_index, multiple_files = "PDF_MULTIPLE_FILES_PAGE_NAME")
| improve this answer | |

You can test below code, it changes the name of the pdf dynamically.

import datetime
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
xfl = r"C:\Mapsfolder\" + str(time.strftime("%Y%m%d-%H%M%S")) + ".pdf"
arcpy.mapping.ExportToPDF(mxd, xfl)
del mxd

hope this solves your problem.

| improve this answer | |
  • Thanks for you suggestion. Now I have made a new mxd, but i have the same problem - it works 2 or 3 times, but after that nothing happens – Malcolm Alexander Oct 29 '19 at 10:22
  • If this solved your problem, you can accept this as answer. – Keshav Sharma Oct 30 '19 at 7:52
  • Thanks but it doesn't seem to make any difference - it works 2 or 3 times, but after that nothing happens – Malcolm Alexander Nov 7 '19 at 10:34

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.