Aspose.Slides for Python on Mac - add_clone Method Is Not Working

I am trying to clone a slide with the following code:

import aspose.slides as slides
import aspose.pydrawing as drawing

license = slides.License()
license.set_license("Aspose.TotalProductFamily.lic")

# Path to a brand-new PPTX with just one simple slide
source_file = "brand_new.pptx"

with slides.Presentation(source_file) as source_prs, \
     slides.Presentation() as target_prs:
    # Try to clone the first (and only) slide
    source_slide = source_prs.slides[0]

    print(source_slide)
    print(target_prs.slides[0])

    dest = target_prs.slides

    dest.add_clone(source_slide)
    target_prs.save("test_output.pptx", slides.export.SaveFormat.PPTX)

print("Minimal clone test completed.")

This fails with the following message:

<aspose.slides.Slide object at 0x103d16530>
<aspose.slides.Slide object at 0x103d165f0>
Traceback (most recent call last): …
dest.add_clone(source_slide)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^
RuntimeError: Proxy error(NullReferenceException): Object reference not set to an instance of an object.

What’s going on?

@maxwellpower

It seems that you are encountering a NullReferenceException when trying to clone a slide using the add_clone method in Aspose.Slides for .NET. This issue can occur if the source slide or the target presentation is not properly initialized or if there are issues with the slide’s content.

Here are a few suggestions to troubleshoot and potentially resolve the issue:

  1. Ensure Proper Initialization: Make sure that both the source and target presentations are correctly initialized. You can check if the source_slide is not null before attempting to clone it.

  2. Save the Presentation: Sometimes, saving the presentation before cloning can resolve underlying issues with the slide’s content. You can save the source presentation to a temporary file or stream before cloning the slide. Here’s an example of how to do this:

    import aspose.slides as slides
    import aspose.pydrawing as drawing
    from io import BytesIO
    
    license = slides.License()
    license.set_license("Aspose.TotalProductFamily.lic")
    
    source_file = "brand_new.pptx"
    
    with slides.Presentation(source_file) as source_prs, \
         slides.Presentation() as target_prs:
        # Save the source presentation to a memory stream
        presentation_stream = BytesIO()
        source_prs.save(presentation_stream, slides.export.SaveFormat.PPTX)
        presentation_stream.seek(0)  # Reset stream position
    
        # Load the presentation from the stream
        with slides.Presentation(presentation_stream) as cloned_source_prs:
            source_slide = cloned_source_prs.slides[0]
            target_prs.slides.add_clone(source_slide)
    
    target_prs.save("test_output.pptx", slides.export.SaveFormat.PPTX)
    print("Minimal clone test completed.")
    
  3. Check for Corrupted Slides: If the source presentation has any corrupted slides or unsupported elements, it may lead to exceptions during cloning. Ensure that the slides in the source presentation are valid.

  4. Review Documentation and Examples: If the issue persists, consider reviewing the official Aspose documentation or related forum posts for additional insights or similar issues encountered by other users.

By following these steps, you should be able to identify the cause of the error and successfully clone the slide. If you continue to experience issues, please provide more details about the source presentation or any specific elements that might be causing the problem.

@maxwellpower,
We are sorry that you encountered this problem. We would greatly appreciate it if you could share more details to help us investigate the issue. Please share the following files and information:

  • “brand_new.pptx” file
  • OS version on which the code was executed
  • Python version you used
  • Aspose.Slides version you used