<?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 Re: ExportToPDF failed with OSError in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/exporttopdf-failed-with-oserror/m-p/1090443#M62118</link>
    <description>&lt;P&gt;I am having the same issue. I can get it to run in one environment but not the other. I've tried with both ArcGIS Desktop and ArcGIS Pro and both are failing on Windows Server 2019 Datacenter. The working environment is&amp;nbsp;Windows Server 2012 R2 Standard.&amp;nbsp;&lt;/P&gt;&lt;P&gt;A possible breakthrough on the non-working server is to kill the python process when I'm finished doing the export. Here is a snippet of code that I'm using with 3.7.10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import signal
pid = os.getpid()
os.kill(pid, signal.SIGTERM)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My initial tests seem to show this is working, but I don't know what other issues this might cause. I am using FireDaemon to manage my service, and I had to adjust some of the lifecycle settings to get it to work.&lt;/P&gt;&lt;P&gt;One other note, this seems to be a &lt;A href="https://support.esri.com/en/bugs/nimbus/QlVHLTAwMDEwNjQ2NA==" target="_self"&gt;BUG-000106464&lt;/A&gt;. There is recent activity on this bug, so hopefully, we get a fix or workaround soon.&lt;/P&gt;&lt;P&gt;edit to add:&lt;BR /&gt;My service always runs one time successfully, then hangs. Perhaps this is different than your issue?&lt;/P&gt;</description>
    <pubDate>Thu, 19 Aug 2021 17:53:41 GMT</pubDate>
    <dc:creator>SamPalmer</dc:creator>
    <dc:date>2021-08-19T17:53:41Z</dc:date>
    <item>
      <title>ExportToPDF failed with OSError</title>
      <link>https://community.esri.com/t5/python-questions/exporttopdf-failed-with-oserror/m-p/1070872#M61435</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;I have a strange behaviour with my script which I wrote for a customer.&lt;/P&gt;&lt;P&gt;Just the relevant lines ...&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
import sys
import logging
import logging.config
from datetime import datetime

# CONFIG Paths
Pdf_Path = r"C:\PrintServer"
Log_Path = r"C:\PrintServer\log"
Aprx_File = r"D:\data\PrintServer\COVID19_Print.aprx"

def main():
    # Input Layout template
    Layout_Template = arcpy.GetParameterAsText(0)

    #open the ProProject    
    try:
        aprx = arcpy.mp.ArcGISProject(Aprx_File)
        layouts = aprx.listLayouts(Layout_Template)
    except:
        raise

    #print each layout found
    out_files = []
    for lyt in layouts:
        try:                
            now = datetime.now()
            tmp_file_name = lyt.name + "_" + now.strftime("%Y%m%d_%H%M%S") + ".pdf"
            Temp_File = os.path.join(arcpy.env.scratchFolder, tmp_file_name)

            #This line always results in an OSError
            lyt.exportToPDF(Temp_File, resolution = 300)

            Output_File = os.path.join(Pdf_Path, tmp_file_name)
            import shutil
            shutil.move(Temp_File, Output_File)

            out_files.append(Output_File)
        except:
            raise

    arcpy.SetParameter(1, out_files)

if __name__ == '__main__':
    try:
        main()
    except:
        import traceback
        logging.error(traceback.format_exc())&lt;/LI-CODE&gt;&lt;P&gt;The idea is to provide a GPService which takes a public WebMap, uses a predefined ArcGIS Pro Project (.aprx) also published with the GPService, reading a layout and printing this layout as pdf document.&lt;/P&gt;&lt;P&gt;In my tests on my machine and three different ArcGIS servers, this has been no problem. Also running on the customers ArcGIS Pro client worked as expected, but when rolling out on the customers server, we always get an OSError when executing the ExportToPDF method.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="2021-06-08_15h38_08.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/16568i4B901169665CA643/image-size/large?v=v2&amp;amp;px=999" role="button" title="2021-06-08_15h38_08.png" alt="2021-06-08_15h38_08.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What we already verified/tested:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;different file directories: hard coded temp folder or the scratch folder from arcgis&lt;/LI&gt;&lt;LI&gt;shortened the file and directory names&lt;/LI&gt;&lt;LI&gt;tripple checked write permissions, we have&lt;/LI&gt;&lt;LI&gt;used different users, even full previliged from their IT department&lt;/LI&gt;&lt;LI&gt;executed the script via GPService or via python shell, both results in the same OSError&lt;/LI&gt;&lt;LI&gt;tested with ExportToJPG and ExportToPNG, both also produces the same error&lt;/LI&gt;&lt;LI&gt;tested, if a PDF program is necessary (it is not)&lt;/LI&gt;&lt;LI&gt;tested, if a PDF in general could be produced with python (is possible)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So, this works:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    #Create the file and append pages
    pdfDoc = arcpy.mp.PDFDocumentCreate(pdfPath)
    pdfDoc.appendPages(referencePdf)

    pdfDoc.saveAndClose()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And now I don't have any other idea.&lt;/P&gt;&lt;P&gt;Anybody of you have any?&lt;/P&gt;&lt;P&gt;Has anybody a deeper look into that tool and can say, why this error could happen?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 07:58:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporttopdf-failed-with-oserror/m-p/1070872#M61435</guid>
      <dc:creator>MaximilianGlas</dc:creator>
      <dc:date>2021-06-22T07:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: ExportToPDF failed with OSError</title>
      <link>https://community.esri.com/t5/python-questions/exporttopdf-failed-with-oserror/m-p/1070877#M61436</link>
      <description>&lt;P&gt;remotely connected??&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.esri.com/en/bugs/nimbus/QlVHLTAwMDEwNzA4NA==" target="_blank"&gt;BUG-000107084: The arcpy.mp module exportToPDF method crashes web t.. (esri.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;but there are 12 bugs historically associated with exportToPDF that don't seem relevant&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.esri.com/en/Search-Results#search?q=ExportToPDF&amp;amp;content-type=Bugs" target="_blank"&gt;Esri Support Search-Results&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Your best bet would be Tech Support&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 08:27:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporttopdf-failed-with-oserror/m-p/1070877#M61436</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-06-22T08:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: ExportToPDF failed with OSError</title>
      <link>https://community.esri.com/t5/python-questions/exporttopdf-failed-with-oserror/m-p/1090443#M62118</link>
      <description>&lt;P&gt;I am having the same issue. I can get it to run in one environment but not the other. I've tried with both ArcGIS Desktop and ArcGIS Pro and both are failing on Windows Server 2019 Datacenter. The working environment is&amp;nbsp;Windows Server 2012 R2 Standard.&amp;nbsp;&lt;/P&gt;&lt;P&gt;A possible breakthrough on the non-working server is to kill the python process when I'm finished doing the export. Here is a snippet of code that I'm using with 3.7.10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import signal
pid = os.getpid()
os.kill(pid, signal.SIGTERM)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My initial tests seem to show this is working, but I don't know what other issues this might cause. I am using FireDaemon to manage my service, and I had to adjust some of the lifecycle settings to get it to work.&lt;/P&gt;&lt;P&gt;One other note, this seems to be a &lt;A href="https://support.esri.com/en/bugs/nimbus/QlVHLTAwMDEwNjQ2NA==" target="_self"&gt;BUG-000106464&lt;/A&gt;. There is recent activity on this bug, so hopefully, we get a fix or workaround soon.&lt;/P&gt;&lt;P&gt;edit to add:&lt;BR /&gt;My service always runs one time successfully, then hangs. Perhaps this is different than your issue?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 17:53:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporttopdf-failed-with-oserror/m-p/1090443#M62118</guid>
      <dc:creator>SamPalmer</dc:creator>
      <dc:date>2021-08-19T17:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: ExportToPDF failed with OSError</title>
      <link>https://community.esri.com/t5/python-questions/exporttopdf-failed-with-oserror/m-p/1091144#M62143</link>
      <description>&lt;DIV class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hi Sam,&lt;/P&gt;&lt;P&gt;it seems that we could locate the reason for our problem.&lt;/P&gt;&lt;P&gt;There were some texts in our layout that were apparently responsible for the problem. When we removed the texts, printing worked without any problems.&lt;BR /&gt;We have found a patch that should fix the problem. Initial tests are promising.&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.esri.com/en/Products/Enterprise/arcgis-server/ArcGIS-Server/10-8#downloads?id=7868" target="_self"&gt;ArcGIS Server 10.8.1 Print Service and Text Element Patch&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Maybe this will work for you too.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 23 Aug 2021 06:56:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporttopdf-failed-with-oserror/m-p/1091144#M62143</guid>
      <dc:creator>MaximilianGlas</dc:creator>
      <dc:date>2021-08-23T06:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: ExportToPDF failed with OSError</title>
      <link>https://community.esri.com/t5/python-questions/exporttopdf-failed-with-oserror/m-p/1091215#M62147</link>
      <description>&lt;P&gt;Max,&lt;/P&gt;&lt;P&gt;Thanks so much for the reply! Unfortunately, I'm not using ArcGIS Server, only clients, so I can't try that patch. I did try renaming the layout and map frame in ArcGIS Pro, but that didn't fix the issue. Killing the python session is still working though, so I think I have a fix for now.&lt;/P&gt;&lt;P&gt;-Sam&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 13:42:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/exporttopdf-failed-with-oserror/m-p/1091215#M62147</guid>
      <dc:creator>SamPalmer</dc:creator>
      <dc:date>2021-08-23T13:42:16Z</dc:date>
    </item>
  </channel>
</rss>

