2

I have a weird issue in exporting the layout to PDF My code is really simple and I have tried in ArcGIS Python IDLE but I have came across the problem.

My Code and error is :

Code:

aprx = arcpy.mp.ArcGISProject("CURRENT")
Layout = aprx.listLayouts()[0]
Layout.exportToPDF(r"C:\1.pdf")

Error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\utils.py", line 191, in fn_
    return fn(*args, **kw)
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\_mp.py", line 975, in exportToPDF
    return convertArcObjectToPythonObject(self._arc_object.exportToPDF(*gp_fixargs((out_pdf, resolution, image_quality, compress_vector_graphics, image_compression, embed_fonts, layers_attributes, georef_info, jpeg_compression_quality, clip_to_elements), True)))
OSError: C\1.pdf
  • 1
    What happens when you try to save it to a directory instead of the root of the C:\ drive and give it a name that starts with a letter, i.e. C:\temp\a1.pdf – user2856 Mar 24 at 2:23
  • I have tried and it worked. Actually, it was part of my script tools and the problem was I was referring to save pdf to project path instead of project folder path. but as curiosity why could not we able to save in C drive. – Dave Kazemi Mar 24 at 2:41
  • 1
    If you’re using CURRENT you need to run the code from within Pro. You can’t run it from outside the app, in Idle. CURRENT doesn’t exist there – KHibma Mar 24 at 2:44
2

If using a filename that starts with a numeral like this:

Layout.exportToPDF(r"C:\1.pdf")

gives that OSError and using one that does not like this:

Layout.exportToPDF(r"C:\temp\test1.pdf")

does not give the error, then it suggests to me that you may not be using supported file naming conventions for ArcGIS Pro. If I can find a link to where these are documented I will add it into this answer.

  • This is highly unlikely to be a Pro problem. Its almost certainly a domain policy setting within the users organization. I'm at a company where I cannot create c:\foo.txt using notepad. – KHibma Mar 25 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.