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:
- different file directories: hard coded temp folder or the scratch folder from arcgis
- shortened the file and directory names
- tripple checked write permissions, we have
- used different users, even full previliged from their IT department
- executed the script via GPService or via python shell, both results in the same OSError
- tested with ExportToJPG and ExportToPNG, both also produces the same error
- tested, if a PDF program is necessary (it is not)
- tested, if a PDF in general could be produced with python (is possible)
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