Select to view content in your preferred language

ExportToPDF with arcpy fails

569
9
03-11-2025 06:06 AM
Dalneberg
Emerging Contributor

I have a pythonscript that exports pdf with arcpy.exportToPDF.

It has worked well until december 2024/january 2025.

It works on my machine (with Windows 11) in Windows scheduler (with option: Run whether user is logged in or not). (I have a runner.bat that runs a pythonfile.)

But it does not work on a Windows Server (We have upgraded from Windows Server 2019 to 2022 but it did not make any difference).

On this Windows server it only works to run when i run it right in the commandtool, or in a windows task scheduler with the option: Run only when the user is logged on.

I have tried with ArcGIS Server on the server, and also tried with only ArcGISPro (3.3) on the server. Both with MicrosoftEdgeWebView2RuntimeInstallerX64 installed (test is done with version 133.0.3065.92 and 134.0.3124.51).

I also tried with a older version of ArcGISPro.

I have all admin permissions on the folders and in task scheduler.

So, the question is what can cause this arcpy.exportToPDF to fail? and without any errormessages.

9 Replies
Marshal
Frequent Contributor

Does it cause the script to hang?  Interesting that it behaves differently on Windows Server vs. Windows 11.  I encountered similar behavior on our Windows Server 2019 box.  The only solution I found at the time was using "Run only when user is logged on" and making sure the account was always logged on.

https://community.esri.com/t5/python-questions/scripts-with-exporttopdf-lock-up-windows-task/m-p/109...

That said, I just did some testing on ArcGIS Pro 3.4 (Windows Server 2019, only ArcGIS installed) after a recent upgrade and it seems to work using "Run whether user is logged on or not".  I will try to conduct further testing over next couple weeks and report back.

0 Kudos
Dalneberg
Emerging Contributor

Hi, thanks, no it does not cause the script to hang, it just stop and without any errors. 
Ok, i will test to install ArcGISPro 3.4 on a windows server and see if it works with that.

0 Kudos
DavidPike
MVP Notable Contributor

Mapped drive locations can be an issue with scheduler, as they're profile-specific.  Your service principal may not have those mappings or arcpy library, or may still be some gpo issue when the box logs in as you. 

I'd be tempted to output somewhere simple such as the C:\ or a UNC path.

Work the problem up from writing a text file with no modules imported, then something basic in arcpy etc. 

0 Kudos
Dalneberg
Emerging Contributor

Hi @DavidPike 
I do not use mapped drive locations, only on C:\
I also have tested to work the problem up, and it always stop at the arcpy.exportToPDF, not at the arcpy.mp.ArcGISProject for example.

My python-script:

import arcpy, os

def main():
print(f"1")
# Ange sökvägar
prjPath = os.path.normpath(r'C:\temp\fme')
outputPath = os.path.normpath(r'C:\temp\fme\testoutput')
print(f"2")
path = os.path.join(prjPath, 'Test_PDFutskrift.aprx')
print(f"2.1")

# Öppna ArcGIS Pro-projektet
p = arcpy.mp.ArcGISProject(path)
print(f"3")

# Lista av layoutnamn
layoutNames = ['A3', 'A2']
for name in layoutNames:
# Hämta layout
print(f"4")
layouts = p.listLayouts(name)
if len(layouts) == 0:
print(f"Layout {name} finns inte i projektet.")
continue
lyt = layouts[0]

# Sökväg för PDF-export
pdfPath = os.path.join(outputPath, f"{name}.pdf")
print(f"Försöker exportera {name} till {pdfPath}...")

# Exportera till PDF
try:
lyt.exportToPDF(pdfPath)
print(f"Lyckades exportera {name} till {pdfPath}.")
except Exception as e:
print(f"Misslyckades med att exportera {name} till PDF: {e}")

if __name__ == "__main__":
main()



0 Kudos
DavidPike
MVP Notable Contributor

Yes I suggested it really to test that the script can write/output something.  If that works, then it then likely excludes any write issues/file and folder permission issues etc.  I'd still suggest trying to output a textfile.

0 Kudos
Dalneberg
Emerging Contributor

Yes, I can write a textfile, and all above the code down to exportToPDF, there it stops without any errors.

0 Kudos
jschuckert
Occasional Contributor

@Dalneberg I have this exact same issue!! For me I had a production script running for well over a year then around the Dec 1st run of the process started failing but only for the pdf export step and only when run from Task Scheduler with the option (I need) "Run whether user is logged on or not" checked.

I have 3 servers (x2 on OS 2016 DataCenter and x1 on Server 2019) all of which I can recreate the same failing behavior. 

I tried pointing the PDF output to the local C Drive which the service account running the script has full permissions on. I also tried older versions of Pro. None of that made a difference. 

I opened an ESRI case, however it is now since closed as they were unable to reproduce the behavior and deemed it something network specific to my environment. 

I have been troubleshooting this ever since with no success!! This is a tricky one...

The best I could find was old ESRI bugs that were very similar, however those have since been resolved. Since ESRI was not able to recreate the issue on their end I seem to be at a dead end. 

0 Kudos
Dalneberg
Emerging Contributor

I now also had I case at ESRI, but they unfortunatley also closed it and they think the problem is in windows and probably has do with some permission in some kind. So now I have a errand on our IT department, hopeful they will find a solution.

0 Kudos
jschuckert
Occasional Contributor

Interesting. We both seem to be stuck in the same loop. Still no solution on my end either...

0 Kudos