Select to view content in your preferred language

pdfDoc.saveAndClose syntax error

635
1
Jump to solution
09-07-2012 11:32 AM
DaveJordan1
Regular Contributor
I am testing a script that will append PDF files together into a sngle document.  The script performs as exspected until it hits the line pdfDoc.saveAndClose and then it throws a syntax error.  It actually creates the combined PDF on disk even though it is throwing the error. 

What is wrong ith this syntax?

import arcpy import os  from os.path import isdir, join, normpath, split   mxd = arcpy.mapping.MapDocument("Current")  wPath = r"Y:\Notification Radius Pkgs\dave500\\" RequestID = "Dave Jordan"  try:  pdfPath = wPath+RequestID+".pdf"  arcpy.AddMessage(pdfPath)  if os.path.exists(pdfPath):   os.remove(pdfPath) #Create the file and append pages  pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfPath)  for file in os.listdir(wPath):   if file.endswith(".pdf"):    arcpy.AddMessage("Adding "+file)    pdfDoc.appendPages(wPath+file)  #Commit changes and delete variable reference  pdfDoc.saveAndClose()  del pdfDoc   except Exception, e:   import traceback   map(arcpy.AddError, traceback.format_exc().split("\n"))   arcpy.AddError(str(e))   
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DaveJordan1
Regular Contributor
Nevermind - as soon as I posted it I saw the problem, I failed to indent properly (It should be in line with the for statement instead of the flsh to the edge)  I am surprised it didn't give thhe indention error...

import arcpy import os  from os.path import isdir, join, normpath, split   mxd = arcpy.mapping.MapDocument("Current")  wPath = r"Y:\Notification Radius Pkgs\dave500\\" RequestID = "Dave Jordan"  try:  pdfPath = wPath+RequestID+".pdf"  arcpy.AddMessage(pdfPath)  if os.path.exists(pdfPath):   os.remove(pdfPath) #Create the file and append pages  pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfPath)  for file in os.listdir(wPath):   if file.endswith(".pdf"):    arcpy.AddMessage("Adding "+file)    pdfDoc.appendPages(wPath+file)  #Commit changes and delete variable reference   pdfDoc.saveAndClose()   del pdfDoc   except Exception, e:   import traceback   map(arcpy.AddError, traceback.format_exc().split("\n"))   arcpy.AddError(str(e))   

View solution in original post

0 Kudos
1 Reply
DaveJordan1
Regular Contributor
Nevermind - as soon as I posted it I saw the problem, I failed to indent properly (It should be in line with the for statement instead of the flsh to the edge)  I am surprised it didn't give thhe indention error...

import arcpy import os  from os.path import isdir, join, normpath, split   mxd = arcpy.mapping.MapDocument("Current")  wPath = r"Y:\Notification Radius Pkgs\dave500\\" RequestID = "Dave Jordan"  try:  pdfPath = wPath+RequestID+".pdf"  arcpy.AddMessage(pdfPath)  if os.path.exists(pdfPath):   os.remove(pdfPath) #Create the file and append pages  pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfPath)  for file in os.listdir(wPath):   if file.endswith(".pdf"):    arcpy.AddMessage("Adding "+file)    pdfDoc.appendPages(wPath+file)  #Commit changes and delete variable reference   pdfDoc.saveAndClose()   del pdfDoc   except Exception, e:   import traceback   map(arcpy.AddError, traceback.format_exc().split("\n"))   arcpy.AddError(str(e))   
0 Kudos