Convert PPTX to jpg in python using GroupDocs.Conversion

Hi,
I need help please.
When i use a sample code to convert pptx to jpg on my application,
I have this erreor bellow.

Exception while calling API: Object reference not set to an instance of an object.

My code is:

                convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(app_sid, app_key)

                # Define convert settings
                settings = groupdocs_conversion_cloud.ConvertSettings()
                settings.storage_name = 'GROUPDOCS_Amazon_S3'
                settings.file_path = 'tmp/archi.pptx'
                settings.format = "jpg"

                convertOptions = groupdocs_conversion_cloud.JpegConvertOptions()
                convertOptions.gray_scale = True
                convertOptions.from_page = 1
                convertOptions.pages_count = 1
                convertOptions.quality = 100
                convertOptions.rotate_angle = 90
                convertOptions.use_pdf = False
                settings.convert_options = convertOptions
                settings.output_path = "tmp/"

                request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
                response = convert_api.convert_document(request)

                print("Successfully converted PPTX to JPEG format: " + str(response))
            except groupdocs_conversion_cloud.ApiException as e:
                    print("Exception while calling API: {0}".format(e.message))
            content_file.seek(0)  # retourner au début du fichier

@Ben77

Please share your sample input PPTX file as well.

Ok, please find it in attachmentarchi.zip (1.4 MB)

1 Like

@Ben77

Please ensure you are using the latest version of GroupDocs.Conversion Cloud SDK for Python, as I am unable to notice any exception using your above code and document with GroupDOcs.Conversion Cloud SDK for Python 23.4.

Yes, i use the latest version.

PS C:\Users\Administrateur\PycharmProjects\securestaff> pip install groupdocs-conversion-cloud
Requirement already satisfied: groupdocs-conversion-cloud in c:\users\administrateur\appdata\local\programs\python\python310\lib\site-packages\groupdocs_conversion_cloud-23.4-py3.10.egg (23.4)
Requirement already satisfied: urllib3>=1.15 in c:\users\administrateur\appdata\local\programs\python\python310\lib\site-packages (from groupdocs-conversion-cloud) (1.26.14)
Requirement already satisfied: six>=1.10 in c:\users\administrateur\appdata\local\programs\python\python310\lib\site-packages (from groupdocs-conversion-cloud) (1.16.0)
Requirement already satisfied: certifi in c:\users\administrateur\appdata\local\programs\python\python310\lib\site-packages (from groupdocs-conversion-cloud) (2022.12.7)
Requirement already satisfied: python-dateutil in c:\users\administrateur\appdata\local\programs\python\python310\lib\site-packages\python_dateutil-2.8.2-py3.10.egg (from groupdocs-conversion-cloud) (2.8.

@Ben77

Please try to convert a document from groupdocs cloud internal storage. Otherwise, please share your complete sample working code for conversion along with your credentials via a private message. For a private message, click on my user icon and use the message option for it. I will try to replicate the issue and guide you accordingly.

Hi Tilal,
apptest.zip (1.4 MB)

you find in attachment my sample code and pptx file.
it’s important to notice that i use flask framework

@Ben77
Thanks for sharing the sample code. I have noticed that you are referring to a file that does not exist in your cloud storage, and secondly, you need to instantiate the ConvertSettings object and ConvertOptions(PngConvertOptions) object separately. And later use the convert_options property of ConvertSetting object to set ConverOptions as follows. Please update your code accordingly. It will resolve the issue.

   # Define convert settings
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path = 'archi.pptx'
        settings.format = 'png'
        settings.output_path = '/'

        convertOptions = groupdocs_conversion_cloud.PngConvertOptions()
        settings.convert_options = convertOptions

Hi, Tilal,

it works fine, thanks for your help.
but i have one last question for you, is it possible to take the pptx file locally and convert it to png and save it locally.

@Ben77

Yes, you can use the ConvertDocumentDirect API method for the conversion from the local drive.