Hi guys,
I have a strange behaviour with my script which I wrote for a customer.
Just the relevant lines ...
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())
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.
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.
What we already verified/tested:
So, this works:
#Create the file and append pages
pdfDoc = arcpy.mp.PDFDocumentCreate(pdfPath)
pdfDoc.appendPages(referencePdf)
pdfDoc.saveAndClose()
And now I don't have any other idea.
Anybody of you have any?
Has anybody a deeper look into that tool and can say, why this error could happen?
Kind regards,
Max
remotely connected??
BUG-000107084: The arcpy.mp module exportToPDF method crashes web t.. (esri.com)
but there are 12 bugs historically associated with exportToPDF that don't seem relevant
Your best bet would be Tech Support
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 Windows Server 2012 R2 Standard.
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
import signal
pid = os.getpid()
os.kill(pid, signal.SIGTERM)
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.
One other note, this seems to be a BUG-000106464. There is recent activity on this bug, so hopefully, we get a fix or workaround soon.
edit to add:
My service always runs one time successfully, then hangs. Perhaps this is different than your issue?
Hi Sam,
it seems that we could locate the reason for our problem.
There were some texts in our layout that were apparently responsible for the problem. When we removed the texts, printing worked without any problems.
We have found a patch that should fix the problem. Initial tests are promising.
ArcGIS Server 10.8.1 Print Service and Text Element Patch
Maybe this will work for you too.
Kind regards,
Max
Kind regards,
Max
Max,
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.
-Sam