<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic pdfDoc.saveAndClose syntax error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/pdfdoc-saveandclose-syntax-error/m-p/604002#M47212</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am testing a script that will append PDF files together into a sngle document.&amp;nbsp; The script performs as exspected until it hits the line pdfDoc.saveAndClose and then it throws a syntax error.&amp;nbsp; It actually creates the combined PDF on disk even though it is throwing the error.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What is wrong ith this syntax?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import os&amp;nbsp; from os.path import isdir, join, normpath, split&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("Current")&amp;nbsp; wPath = r"Y:\Notification Radius Pkgs\dave500\\" RequestID = "Dave Jordan"&amp;nbsp; try:&amp;nbsp; pdfPath = wPath+RequestID+".pdf"&amp;nbsp; arcpy.AddMessage(pdfPath)&amp;nbsp; if os.path.exists(pdfPath): &amp;nbsp; os.remove(pdfPath) #Create the file and append pages&amp;nbsp; pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfPath)&amp;nbsp; for file in os.listdir(wPath): &amp;nbsp; if file.endswith(".pdf"): &amp;nbsp;&amp;nbsp; arcpy.AddMessage("Adding "+file) &amp;nbsp;&amp;nbsp; pdfDoc.appendPages(wPath+file)&amp;nbsp; #Commit changes and delete variable reference&amp;nbsp; pdfDoc.saveAndClose()&amp;nbsp; del pdfDoc&amp;nbsp;&amp;nbsp; except Exception, e: &amp;nbsp; import traceback &amp;nbsp; map(arcpy.AddError, traceback.format_exc().split("\n")) &amp;nbsp; arcpy.AddError(str(e)) &amp;nbsp; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 07 Sep 2012 18:32:58 GMT</pubDate>
    <dc:creator>DaveJordan1</dc:creator>
    <dc:date>2012-09-07T18:32:58Z</dc:date>
    <item>
      <title>pdfDoc.saveAndClose syntax error</title>
      <link>https://community.esri.com/t5/python-questions/pdfdoc-saveandclose-syntax-error/m-p/604002#M47212</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am testing a script that will append PDF files together into a sngle document.&amp;nbsp; The script performs as exspected until it hits the line pdfDoc.saveAndClose and then it throws a syntax error.&amp;nbsp; It actually creates the combined PDF on disk even though it is throwing the error.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What is wrong ith this syntax?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import os&amp;nbsp; from os.path import isdir, join, normpath, split&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("Current")&amp;nbsp; wPath = r"Y:\Notification Radius Pkgs\dave500\\" RequestID = "Dave Jordan"&amp;nbsp; try:&amp;nbsp; pdfPath = wPath+RequestID+".pdf"&amp;nbsp; arcpy.AddMessage(pdfPath)&amp;nbsp; if os.path.exists(pdfPath): &amp;nbsp; os.remove(pdfPath) #Create the file and append pages&amp;nbsp; pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfPath)&amp;nbsp; for file in os.listdir(wPath): &amp;nbsp; if file.endswith(".pdf"): &amp;nbsp;&amp;nbsp; arcpy.AddMessage("Adding "+file) &amp;nbsp;&amp;nbsp; pdfDoc.appendPages(wPath+file)&amp;nbsp; #Commit changes and delete variable reference&amp;nbsp; pdfDoc.saveAndClose()&amp;nbsp; del pdfDoc&amp;nbsp;&amp;nbsp; except Exception, e: &amp;nbsp; import traceback &amp;nbsp; map(arcpy.AddError, traceback.format_exc().split("\n")) &amp;nbsp; arcpy.AddError(str(e)) &amp;nbsp; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Sep 2012 18:32:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pdfdoc-saveandclose-syntax-error/m-p/604002#M47212</guid>
      <dc:creator>DaveJordan1</dc:creator>
      <dc:date>2012-09-07T18:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: pdfDoc.saveAndClose syntax error</title>
      <link>https://community.esri.com/t5/python-questions/pdfdoc-saveandclose-syntax-error/m-p/604003#M47213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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)&amp;nbsp; I am surprised it didn't give thhe indention error...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import os&amp;nbsp; from os.path import isdir, join, normpath, split&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("Current")&amp;nbsp; wPath = r"Y:\Notification Radius Pkgs\dave500\\" RequestID = "Dave Jordan"&amp;nbsp; try:&amp;nbsp; pdfPath = wPath+RequestID+".pdf"&amp;nbsp; arcpy.AddMessage(pdfPath)&amp;nbsp; if os.path.exists(pdfPath): &amp;nbsp; os.remove(pdfPath) #Create the file and append pages&amp;nbsp; pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfPath)&amp;nbsp; for file in os.listdir(wPath): &amp;nbsp; if file.endswith(".pdf"): &amp;nbsp;&amp;nbsp; arcpy.AddMessage("Adding "+file) &amp;nbsp;&amp;nbsp; pdfDoc.appendPages(wPath+file)&amp;nbsp; #Commit changes and delete variable reference&amp;nbsp;&amp;nbsp; pdfDoc.saveAndClose()&amp;nbsp;&amp;nbsp; del pdfDoc&amp;nbsp;&amp;nbsp; except Exception, e: &amp;nbsp; import traceback &amp;nbsp; map(arcpy.AddError, traceback.format_exc().split("\n")) &amp;nbsp; arcpy.AddError(str(e)) &amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Sep 2012 18:38:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pdfdoc-saveandclose-syntax-error/m-p/604003#M47213</guid>
      <dc:creator>DaveJordan1</dc:creator>
      <dc:date>2012-09-07T18:38:28Z</dc:date>
    </item>
  </channel>
</rss>

